Table of Contents
- Sending emails from the script may be a very useful functionality within the web application. Most of the websites used the e-mail sending feature to send the notifications to the user. If your web application developed with PHP or uses PHP, it’s very easy to send email from the script using PHP.
- PHP provides a simple thanks to send emails from the web site. You’ll send text or HTML email with mail () function in PHP. But sometimes email functionality must be extended for sending an attachment with the mail. During this tutorial, we’ll show you ways to send email with attachment in PHP.
- In the example script, we’ll make it simple to send text or HTML email including any sorts of files as an attachment (like image, .doc, .docx, .pdf, .txt, etc.) Using PHP.
Send HTML Email with Attachment
The PHP mail () function with some MIME type headers is used to send email with attachment in PHP. Within the following example code, MIME and Content-Type headers are used with mail () function to send email with attachment using PHP.
- $to – Recipient email address.
- $from – Sender email address.
- $fromname – Sender name.
- $subject – Subject of the e-mail.
- $file – Relative path of the file that you simply want to connect with the e-mail .
- $htmlcontent – Body content of the email (Text or HTML).
The following script allows you to send both sorts of messages (text or HTML) with an attachment file to the e-mail.
The example script allows you to send one attachment to the email, to send an email with multiple attachments follow this tutorial – Send Email with Multiple Attachments in PHP
Sending Email to Multiple Recipients:
- You can send email to the multiple recipients directly with Cc and Bcc headers.
- Use the Cc and Bcc headers for sending email with attachment to multiple recipients in PHP.
Conclusion
- Here we’ve provided the easiest thanks to send email with attachment in PHP.
- You don’t have to include any library to send HTML email with attachment.
- Using PHP default mail () function you’ll easily send email with attachment.