How to send email with email attachment
How to send email with email attachment
php send email with attachment
i take snippet from this place Click here
In this site, snippet works fine,
Even i got the mail, but attachment is not working, am getting attment as noname with 0kb
5 Answers 5
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
If you are NOT trying to learn how to do it by hand, and just want to send an email with attachment, then you are better of using some sort of library for that. I recommend SwiftMailer, I tried a lot of libraries and this one works best. Check how easy it is to add an attachment using SwiftMailer here: http://swiftmailer.org/docs/attaching-files
Your best bet is to use the Mime Mail PEAR library for handling attachments. It’s much easier and cleaner and you’ll be less prone to errors.
You can attach files to an email simply like this:
If you just want to send a simple form with a single attachment this code is probably the best and easiest thing to use is the following code it works well.
I did not see the answer to your question anywhere above, so I will attempt to provide a little more information that might help.
I had the same exact problem just today. I built a series of PDF files, which then were converted to a single tar.gz file and this file bundle I wanted to email to a human processing agent who would respond to these documents in kind. However, when I used the various scripts to generate the correct MIME message format, I ended up sending an attachment that was 0 kB in total size with the name «noname».
With so many people all providing the same answer, I thought to myself that there answers must be correct and that the problem must be somewhere else. The answer to the problem is not the formatting of the message content, nor is it in your headers. Everything there is correct. The problem lies in the mail applications that exist between your application and the recipient e-mail address.
I moved my code to a production server and the message sent without any problems, and the same file that previously sent as «noname 0kb» now was sent as «MikeyPoochigian_2013_05_10__16_28_27.tar.gz 241kb».
I don’t know yet what causes this particular failure, but I imagine it is a similar answer to one that I learned earlier this year when my mail application was sending to gmail but not sending to other mail servers. In that particular case, the mail applications were filtering content for SPAM between my development laptop (which had the internal domain of DevelopmentLaptop.local) and the final e-mail address. Because my originating server sent from the domain «DovelopmentLaptop.local», and because this domain was not registered with any DNS as a known address, those mail servers interpreted my test messages as spam. I suspect the same problem is interfering now with the messages that are being sent.
Long answer now short (if that is possible), try porting your code to a production server with a registered public domain and see if it works. If it does, then it is not your code that needs to be fixed. Your code is likely to be fine.
How To Write an Email With an Attachment (With Examples and Tips)
By Indeed Editorial Team
Updated May 18, 2022 | Published January 13, 2021
Updated May 18, 2022
Published January 13, 2021
Copy to Clipboard
Knowing how to write and send an email with an attachment can increase your productivity by improving how you communicate with others. Emails with attached files are a valuable communication tool, but they require knowledge and etiquette. In this article, we discuss what an email attachment is, how to mention the attachment in your email, how to include the attachment and examples to use as a guide.
What is an email attachment?
An email attachment is a file that one person sends to another with an accompanying email. Its purpose is usually to enhance the value or benefit that the email offers the reader by providing additional content that you can’t express in the body of the email. The attachment can have different formats and sizes, with the most typical attachments being large text files, various types of documents, spreadsheets, scanned files, forms, pictures and videos.
Should you mention the attachment in the email’s body?
Like with most other forms of communication, you need to follow some rules and guidelines when communicating by email. When it comes to email attachments, it is recommended that you mention the attached file somewhere in the email’s body before sending it, in both formal and informal situations.
Although it is usually easy to recognize an email that has attachments—since it comes with an extra icon next to the subject line that indicates the presence of an attachment—some recipients do not open emails with attachments unless they know exactly what they are and where they come from. Usually, the reason for this is to avoid exposing themselves to a potentially malicious attachment, such as a computer virus, that could affect their device or other files.
How to write an email with an attachment
Consider these five steps when composing and sending an email containing an attachment:
1. Determine what files you wish to send
Before writing the email, you should know exactly what file you are about to send and where it is located on your device’s hard drive or memory drive. Knowing what file or files you are about to send is important because you need to mention them in the email’s text, and knowing their location can help you quickly locate and attach them before sending the email.
2. Write the email’s subject line
The next step is composing the email’s subject line. As many potential recipients tend to disregard emails with attachments unless they know what the attached files are, the email’s subject should reflect the fact that it contains one or more attached files and provide information regarding what they are.
3. Compose the email’s body
If the attachments are the only reason you need to send a message, the email’s body can simply be a brief description of the attached files. If the attached files are only a part of what the email aims to transmit, they need to be mentioned somewhere in the body, ideally with a short sentence that specifies what they are. Sending an email with attachments and no text is not recommended, as the recipient or their email provider may confuse them with spam.
4. Attach the files
After composing the email, the final step before sending it is attaching the necessary file or files. However, this step can take place at any time during the composing and sending process. Many senders prefer to attach the files before writing the email because it eliminates the risk of forgetting to attach them altogether.
5. Review and send the email
Once the email’s subject and body are written and the files are attached, you can do a quick proofread and send the email to the recipient.
Tips for writing emails with attachments
Consider these tips to help you write and send emails with attached files:
Make sure the attachment is in an appropriate file format
You need to make sure that the recipient can access the files you are about to send. If you are sending text files, spreadsheets, scanned documents, pictures or any other type of files, it’s important to use a common file format to maximize the odds that the recipient can open the attachment.
Try to limit the attachment file’s size
Most email servers have a size limit for attachments, so it is recommended that you limit the size of the attached files as much as you can. This can be done in several ways, depending on the nature of the files. Most files will be significantly smaller if you use compressing software to convert them to zip files. You can also resize pictures with unnecessarily high resolutions to greatly reduce their file size, and you can compress multiple text files into a single PDF file.
Consider sending a link instead
When you send professional emails, consider including a link that contains the information you are about to attach instead of attaching the actual files. Depending on the situation, it could be a link to your resume, a link to the pictures or text files you are about to send or simply a link to the location where you previously uploaded the files. This could make it easier and safer for the recipient to access the information.
Avoid sending many unrelated files within the same email
Consider sending multiple emails to the same recipient if you want to send them many different files that have no relation to each other. This way, you can avoid any confusion by using each email’s subject line and body to describe the respective attached file, and it will be easier for the recipient to find what they need at a later date.
Examples of emails with attachments
Here are two examples of how to write an email with an attachment:
Example 1
Subject line: Medical supply shipment update with attached PDF
Dear Dr. Matthews,
In response to your inquiry regarding the next shipment of medical supplies arriving at the Saint Francis General Hospital in January 2021, please find attached the name and quantity of every supply in PDF format.
Thank you for your inquiry, and feel free to write back if you have any further questions regarding the shipment or any other matter that we can help you with.
Sincerely,
Michael Gilmour
Johnson Medical
Example 2
Subject line: Pictures from our trip to Cancun
Dear Mary,
I’ve attached the best 10 pictures from our Cancun trip to this email. I will be sending you more as soon as I get them from John.
I hope you like them, and I’m looking forward to our next adventure!
How to send email with attachment using InputStream and Spring?
The situation is like this:
First, we generate a file in the memory, we can get a InputStream object. Second the InputStream object must be send as a attachment of a email. The language is Java, we use Spring to send email.
But I get an exception:
Passed-in Resource contains an open stream: invalid argument. JavaMail requires an InputStreamSource that creates a fresh stream for every call.
5 Answers 5
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
It is quite simple:
Have a look at the spring reference chapter 24.3 Using the JavaMail MimeMessageHelper
The example is from there, I think it do want you want to do:
if you want to use a Stream, then you can use
instead of FileSystemResource
You can make simple implementation of InputStreamSource and pass fresh InputStream in it, as requested:
The working examples are:
1) Attachment is an InputStreamSource interface
2) Attachment is an DataSource interface
The explanation:
Passed-in Resource contains an open stream: invalid argument. JavaMail requires an InputStreamSource that creates a fresh stream for every call.
This message could appear if the developer use an implementation of InputStreamSource that return true in the isOpen() method.
There is a special check in the method MimeMessageHelper#addAttacment() :
InputStreamResource#isOpen() always return true that makes impossible to use this implementation as an attachment:
How can I send an email with attachments from a PHP form?
How can I send an email with attachments from a PHP form?
4 Answers 4
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
It’s probably best to use an existing tool, as others have suggested in their answers. However, if you want to roll your own or just understand how, keep reading.
The HTML
There are really just two requirements in your HTML for sending file attachments.
If you have both of these, the browser will upload any attached files along with the form submission.
Side note: These are saved as temporary files on the server. For this example, we’ll take their data and email it, but if you move the temporary files to a permanent location, you’ve just created a file upload form.
The MIME Email Format
This tutorial is great for understanding how to build up a MIME email (which can contain HTML content, a plain text version, attachments, etc) in PHP. I used it as a starting point.
Basically, you do three things:
The PHP
Side note on file size limits
php.ini has some settings that limit attachment size. See this discussion for more info.
An Example PHP Function
I created the following function, which can be included on the page and used to gather up any file attachments submitted with a form. Feel free to use it and/or adapt it for your needs.
The total attachment limit is arbitrary, but large amounts may bog down the mail() script or be rejected by a sending or receiving email server. Do your own testing.
(Note: The mail() function in PHP depends on information in php.ini to know how to send your email.)
If you want to see what’s going on here, comment out the call to mail() and have it echo the output to your screen instead.
How to write email with attachment + 20 samples that work every time
Sending files via email is easy, you may say. But are you sending them the right way?
Adding attachments in an email is not just clicking the paperclip icon in your mailbox. It’s much more than that.
To help you avoid some common pitfalls and communicate more effectively, we have curated a list of best practices for email attachments and 20 excellent samples across multiple situations. These rules are basic, timeless, and can be applied in most contexts. Whether you’re a student, an HR manager, or an employer, they work like a charm. Learn about how to write email with attachment files once, and improve your professional life forever.
Table of contents
💡What is an email attachment? |
Any file attached to your email is called an attachment. There are many types of email attachments, but the most common ones are video attachments, PDF attachments, image attachments, and spreadsheets.
Email attachment is an invaluable tool for online communication, both in your personal and professional life.
How to write email with attachment file?
1. Attachment size: the smaller, the better
Did you know that Google’s attachment size limit is 25MB? For Outlook and Apple Mail, this number is even smaller, only 20MB.
Here are more details of maximum attachment file size from multiple email services:
The reason why these providers set maximum email size limits is mainly security issues. The file size restriction protects the email system from being bombarded by overly large files and spam, which can cause possible disfunction to the whole system.
When the attachment size exceeds the limitation, an error message appears, letting you know that files can’t be sent.
Sending a file in small size not only lets you send it quicker but also let recipients download it faster and most importantly, they can save a tremendous amount of storage space.
So, how to send large files via email?
Don’t send files over 10MB. When your file is adding up to several MB, consider compressing or uploading them to a Cloud.
To compress a file, there are several handy tools you can use:
That’s how you make a file smaller to send through email.
The second option is uploading the file to a Cloud. Then, share this link via your email for your recipients.
2. When in doubt, use PDF
Excluding some formats blocked by Gmail, most formats are allowed.
But just because you can send an attachment successfully doesn’t mean your recipient can open it successfully.
In fact, to read a file, recipients need the support of certain programs.
That’s why when in doubt, use PDF. It’s a simple solution. It’s a friendly format and can be read on most computers and mobile devices.
Here are 2 common ways to convert a file to PDF online.
With this online tool, you just need to drag and drop a file from your computer into the website to convert it to PDF. It works for Word, PPT, Excel, JPG. The Acrobat online toolkit also has a lot more cool features as below.
Small PDF Converter helps you convert common Microsoft Office formats like Word, PDF, PPT, Excel to PDF and vice versa. Check out the website to explore the full set of tools.
If you are running a Magento online store, try FREE Magezon Email Attachment for Magento 2. It automatically attaches PDF invoices, shipments, and Credit Memos to your transactional emails.
3. Use a link as an attachment alternative
If I could only choose 1 tip to tell you about How to write email with attachment file, that would be using a link. Let me tell you why.
In many cases, a link can deliver the same content as attachments and add up even more mutual benefits to both sender and receiver.
To the sender, links can save them from the frustration of sending capacity, formats, etc.
To the receiver, most links can be opened with an Internet connection, whether on a computer or mobile device.
That’s why we recommend it for you as one of the best way to send email with attachments.
What’s more, it makes the email look cleaner. Who doesn’t like a simple, productive email right?
When including a link, remember 2 tips.
Tip #1. Use the Insert Link feature of Gmail.
This feature helps you turn text into an anchor text.
Tip #2: Shorten the link.
Sometimes, to avoid a lengthy, clumsy link, you better shorten it. To quickly make a shortened link, try bit.ly or cutt.ly. They are quite popular and easy to use.
4. Always name the files properly
It’s okay to use a random name for your files in your computer because after all, who cares?
But this harmless practice could turn out to be harmful if those randomly named files “accidentally” landed into your recipients’ mail boxes.
Prevent this by always naming your files properly, especially the files you want to share with others.
#Do:
#Don’t:
Most importantly, be consistent. Find a name formula you like and stick with it. Otherwise, your file names will mess up, sooner or later.
5. Attach files before drafting the body
Make sure you always attach files. The best practice is to do it before you start with the body. This way, you can save another embarrassing follow-up email saying “I forgot to attach the file”.
Free Magento 2 Email Attachments extension allows users to add attachments such as PDF Invoice, Shipment, Credit Memo, and additional files in the sale emails. Upon sending those emails, users can have full control over the type of files, the number of files, and many other options. |
6. Only attach a document when it’s important
Did you know that 121 is the number of emails an average office worker receives per day?
So don’t mess up with their mailboxes.
Send attachments via email only when necessary. Use a link or copy-paste the information directly to the email body whenever you can.
7. Let recipients know that you attached a file in the email
There are cases when you don’t necessarily need to mention the attachments. That’s when both sides already acknowledge the sole purpose of email is about the attachments. But even in that case, adding something like “Here is [your attachment name]” won’t hurt.
In most other cases, letting recipients know about your attachments will make your email clear and polite. It helps your recipients know what to expect.
Here are some tips when you attach documents to your email:
To inform recipients, be concise and informative. You need to tell them what the files are about and how many numbers of files you attached.
Many people find lines such as “Please, find attached” and PFA boring and repetitive.
That’s why we have found some alternatives to make your email more natural.
4 ways to write email with attachments are:
Note: Use “Attached” in your email instead of “Enclosed” because “Enclosed” is a phrase for physical mails.
8. Double-check
Many of us check grammar and spelling mistakes but forget to do the same thing with the email attachments. As a result, it’s very common that people attach the wrong files or forget to attach files to their emails.
To avoid those “oops” moments, make sure you check everything before sending it. Because better safe than sorry.
In case you’ve made the mistake, follow the golden rules below to fix it.
20 samples of how to write email with attachment
In the past, when someone sent a mail with a physical attachment, they would write:” Enclosed is …” on the letter.
But now, things have changed. We send more emails than ever. When you send an email with attachment, there are many ways to say “I have attached the document to this email”.
Here are 20 ways to eliminate the question “How to communicate that an email has an attachment?”.
Sending attachments to clients
1.Testimonial
I just wanted to reach out because I noticed that you recently requested more info about ProfitFirst. I am Jesse, a Customer Support agent at ProfitFirst. We’re a pricing platform to help small businesses set a successful, data-backed pricing strategy.
I also want to pass along a testimonial video from one of our customers, Robert. After six months of adjusting his pricing with ProfitFirst, he increased his company’s operating profit margin by 5% and their profit by 20%.
Please don’t hesitate to reply to this email with any questions.
2.Monthly report
Hope your week is going well. We wanted to send over our monthly report to give you an idea of how things were looking in August.
It shows that we are still on track to hit out 5% revenue growth numbers by the end of the year, even with the slight dip we saw in revenue this month.
Let me know what you think. We will discuss it all in the next meeting.
3.Meeting reminder
Dear BBS Stakeholder,
This message is a reminder of the BBS stakeholder meeting on December 1, 2017, at 10:00am in New York. You will find attached a draft meeting agenda for your review. Please find attached also the summary of logistics. This includes the location of the meeting as well as nearby hotels, train stations, and airports.
By the end of next week, we will send you the other documents. These include the stakeholder comments on the first draft of the Yearly Plan and a confirmed meeting agenda. It is hoped that this will update all stakeholders on the Yearly Plan status even if you cannot attend the meeting in person.
4.Invitation
I enclosed a letter from Oslo Freedom Forum founder Thor Havorssen inviting you to join him in Oslo. for the Dec. 11th Prize ceremony. Let me know if you have any questions.
Vice President of Strategy
Oslo Freedom Forum
5.Follow-up email with new data
I hope you are doing well. I am reaching out on behalf of the Yesware, whose email data you’ve featured in past pieces from Fast Company. I’m excited to share that we just released new data this week!
I’m attaching a guide that we put together that lists 9 findings from 115,000,000 tracked emails.
We think you’ll find this especially interesting because so many of our findings go against the grain of common opinion. Most email marketing thought leaders preach to use subject lines like “quick question”, etc. In fact, these subject lines actually hurt open and reply rate. Our study shows that they’re actually in the bottom 10 of all subject lines sent.
Are you interested in featuring any of this data?
Looking forward to hearing from you. Have a great day!
6.Sending a contract copy
We have received your payment and contract for the 15th Parson Business Show.
For your record, we have attached a signed copy of the contract.
Please let us know if you have any questions between now and then.
7.Proposal
It was great chatting with you on Friday about your WordPress redesign project.
As discussed during the call, I am sending you a detailed proposal and scope of work.
This project reminds me of Kostas Inc. Their website redesign was completed by me in 5 weeks (3 weeks ahead of schedule). I am confident I can deliver the same type of quality for your team at Magen as well.
If everything is crystal-clear, and you are ready to proceed – simply execute the agreement, and I can start on Phase 1 right away.
If you have any questions, please let me know, and I am happy to set up a call next week,
8.Business introduction
I would like to introduce our organization Mates Cleaners Limited that specializes in the business of providing cleaning services to various office premises.
We have been specializing in this business for over 20 years. Our client list includes the reputed organizations in the cities.
Besides cleaning services, we also provide plumbing service and cleaning of the sewage pipes and trains.
I would be highly grateful if you consider us for providing cleaning services to your office premises. I am also attaching a PDF file stating our quotation. In case of any further queries, you can mail us or call us at 03039-3933-9493.
9.Goods information
Thank you for your email of Sep. 6th 2015.
We are able to produce 3 series of starter batteries, namely BCI (Battery council international), DIN (German standard), and JIS (Japanese standard).
From your website, I get to know that your company has kept a long-term business relationship with some Japanese carmakers. So I figure the batteries you are using should be the JIS series.
Here is the specification of this series of batteries for your reference.
We hope our products can meet your needs and we may establish a long-term business relationship.
10.Invoice
Thank you for your recent business with us. We have attached a detailed copy of Invoice #10 to this email.
11.Shipment
Dear Kristen McCormick,
We are planning to ship the following items next week but due to the Coronavirus, we have postponed the below shipment.
Please check the attached for new shipping info, the shipping instructions, and advice if we should still proceed.
If you have no problem with this shipment time, we will proceed with the shipment.
12.Purchase Order
In the enclosure to this message please find Purchase Order in the PDF file format.
Thanks and if you have any question, or require further assistance, please don;t hesitate to email.
Sending attachments to colleagues
13.Review contract
This is the contract of our new freelance designer who starts working with us next month.
Could you please review the contract by Friday, August 14? I will greatly appreciate your feedback!
14.Apology for sending the wrong attachment
I would like to express my apologies to you for sending you the wrong document yesterday. The file you originally requested has been attached to this email. Kindly discard the wrong document.
I regret causing you any inconvenience that may have occurred owing to my mistake. I hope it didn’t cause any trouble.
15.Monthly results
However, there is an increase in the churn rate. We lost 3% more customers than usual. I am not sure it’s seasonal or not so I’ll follow up on this one.
Please find attached the executive reports for the previous month.
16.Audit report
Attached is the Final BCP Internal Audit report. The purpose of the audit was to perform a comprehensive independent internal audit of CO-OP’s Business Continuity Planning process (BCP). Our assessment of the current control environment resulted in an “Effective” report rating.
The report will be presented to the Audit Committee during the next Audit Committee Meeting.
Internal Audit would like to thank the management for making this audit a success!
Please feel free to contact me with any questions/comments.
Magie Shaker, CPA
Internal Audit Manager
Sending resume and cover letter
17.Sending resume after seeing a vacancy on the company website
I am responding to your job vacancy posting on your company website for a Business Advisor (REF:244LK), and I wish to be considered for the position.
Please find attached my resume and cover letter for your consideration.
Thank you for taking the time to consider my application for this role, and I look forward to meeting you in the near future.
18.Follow up after a job fair
It’s Noah Jacobs and we met at today’s Amelia job fair. I know your inbox is probably a busy place, but I just wanted to say Thank You for talking to me today.
As I mentioned, I would be excited to get a chance for an interview for the position of Senior Business Analyst you’re currently offering. I believe that both my soft and hard skills are strongly in line with your requirements.
Let me know if you’d like any additional information.
I also attached my resume, just in case.
Thanks again and I hope to hear from you soon.
19.Sending a resume for Event Manager position
I am very interested in applying for the Event Manager position at Tamson. Please find attached my resume and cover letter for your consideration.
With 10 years of experience in event management, I believe I would be a strong fit for this position.
Thank you very much for reviewing my application. I look forward to hearing from you regarding the next step.
20.Sending a resume for the Editorial Manager position
I am writing to express my interest in the Editorial Manager position at ABCD, Inc.
My combination of creative talent, technical expertise, and experience managing both writers and projects makes me an ideal candidate for the position.
My cover letter detailing my qualifications and my resume are attached for your review.
Thank you for your time and consideration. I look forward to speaking with you about this employment opportunity.
Wrap up
Like many things else in life, there are basic rules for sending email attachments. Following those proper email etiquettes will significantly increase your productivity and your professional presentation.
But remember that you can always adjust the rules, depending on your context and unique style. Questions like “How well do you know the recipient?” or “Does the recipient prefer a file or a link in the attachment?” surely influence the way you create your email.
Источники информации:
- http://www.indeed.com/career-advice/career-development/how-to-write-email-with-attachment
- http://stackoverflow.com/questions/5677490/how-to-send-email-with-attachment-using-inputstream-and-spring
- http://stackoverflow.com/questions/1330626/how-can-i-send-an-email-with-attachments-from-a-php-form
- http://blog.magezon.com/how-to-write-email-with-attachment-sample/