
September 4th, 2009, 06:33 AM
|
 |
|
|
Join Date: Jun 2006
Location: Salem, OH
|
|
Here. You'll need to use something like this. And since I'm nice, it also auto-detects the mime-type of the attached file.
php Code:
Original
- php Code |
|
|
|
<?php //define the receiver of the email define('MAIL_RCPT') = 'youraddress@example.com'; //define the sender of the email define('MAIL_SENDER') = 'webmaster@example.com'; //define the subject of the email define('MAIL_SUBJECT') = 'Test email with attachment'; //supply the text and html versions of your email message $text = ''; $html = ''; //provide path to the file to be attached $file = ''; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash //define the headers we want passed. Note that they are separated with \r\n $headers = 'From: ' . MAIL_SENDER . "\r\nReply-To: " . MAIL_SENDER; //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 //define the body of the message. $body = "--PHP-mixed-{$random_hash}\r\n" . "Content-Type: multipart/alternative; boundary=\"PHP-alt-{$random_hash}\"\r\n" . "--PHP-alt-{$random_hash}\r\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" . "{$text}\r\n\r\n" . "--PHP-alt-{$random_hash}\r\n\r\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" . "{$html}\r\n\r\n" . "--PHP-alt-{$random_hash}--\r\n\r\n" . "--PHP-mixed-{$random_hash}\r\n" . "Content-Type: " . mime_content_type ($file) . "; name=\"" . basename($file) . "\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-Disposition: attachment\r\n\r\n" . "{$attachment}\r\n" . "--PHP-mixed-{$random_hash}--\r\n\r\n"; //send the email $mail_sent = @ mail(MAIL_RCPT, MAIL_SUBJECT, $body, $headers ); ?>
Last edited by Nilpo : September 4th, 2009 at 06:35 AM.
|