note 38801 deleted from function.mail by irchtml
| From: | irchtml@php.net | Date: | Sat, 28 Feb 2004 20:02:41 +0000 |
| Subject: | note 38801 deleted from function.mail by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65944@lists.php.net to get a copy of this message | ||
Note Submitter: Jan Philipp Fiedler
----
To add an attachment to a mail:
<?php
function mail_attach($to, $from, $subject, $message, $file) {
// $to Recipient
// $from Sender (like "email@domain.com" or "Name <email@domain.com>")
// $subject Subject
// $message Content
// $file File (on server) to attach
$mime_boundary = "<<<:" . md5(uniqid(mt_rand(), 1));
$data = chunk_split(base64_encode(implode("", file($file))));
$header = "From: ".$from."\r\n";
$header.= "To: ".$to."\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: multipart/mixed;\r\n";
$header.= " boundary=\"".$mime_boundary."\"\r\n";
$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content.= $message."\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Disposition: attachment;\r\n";
$content.= "Content-Type: Application/Octet-Stream;
name=\"".$file."\"\r\n";
$content.= "Content-Transfer-Encoding: base64\r\n\r\n";
$content.= $data."\r\n";
$content.= "--" . $mime_boundary . "\r\n";
if(mail($to, $subject, $content, $header)) {
return TRUE;
}
return FALSE;
}
mail_attach($to, "Sender <sender@address.com>", "Subject", $text,
"./mydir/file.jpg");
?>