note 16767 added to function.mail
| From: | daniil at nycfoto dot com | Date: | Mon, 12 Nov 2001 21:27:46 +0000 |
| Subject: | note 16767 added to function.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-20766@lists.php.net to get a copy of this message | ||
Code below works for me:
$to = 'someone@somewhere.com';
$from = 'my@myself.com';
$subject = 'Image attached';
$boundary = "====" . time() . "====";
$headers = "From: $from\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";
$file = 'some.jpg';
if (file_exists($file))
{
if (!($fp = fopen($file, "rb")))
{
print "bummer";
exit;
}
$contents = fread($fp, filesize($file));
$image = base64_encode($contents);
fclose($fp);
}
else
print "Can't find: $file";
$boundary = "--" . $boundary;
$message = $boundary . "\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n\n\n";
$message .= "Attached find an image\n";
$message .= $boundary . "\n";
$message .= "Content-Type: image/jpeg; name=\"some.jpg\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment; filename=\"some.jpg\"\n\n\n";
$message .= $image . "\n$boundary--";
mail($to, $subject, $message, $headers);
--
http://www.php.net/manual/en/function.mail.php
http://master.php.net/manage/user-notes.php?action=edit+16767
http://master.php.net/manage/user-notes.php?action=delete+16767
http://master.php.net/manage/user-notes.php?action=reject+16767