note 16767 deleted from function.mail by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 01:56:50 +0000 |
| Subject: | note 16767 deleted from function.mail by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-21791@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);