1
Votes

Sending Email with Attachment using PHP

Posted By tamilsolai on Mar 16, 2010   FROM: advancedphptutorial.blogspot.com report abuse

PHP Email Attachment, eMail Attachments Using PHP, sendmail attachment php

The last variation that we will consider is email with attachments. To send an email with attachment we need to use the multipart/mixed MIME type that specifies that mixed types will be included in the email. Moreover, we want to use multipart/alternative MIME type to send both plain-text and HTML version of the email.
Have a look at the example:
<?php
//define the receiver of the email
$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test email with attachment';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks

Read Full Story from advancedphptutorial.blogspot.com

Post new comment

  • Allowed HTML tags: <a> <strong> <ul> <ol> <li> <table> <tr> <td> <tbody> <embed> <object> <param> <b> <p> <i> <div> <h3> <h4> <br> <img> <style>
  • Lines and paragraphs break automatically.

More information about formatting options