Hi all,
I have a function which sends html emails, and inserts an image inline in the body of the email, whereever I want it to be.
So far so good..
My question is, how can I insert all the images I want in the email, not just one?
The code for inserting the one image is like this:
function mail_img_kvittering($to, $from, $subject, $body)
{
$boundary = md5(rand());
$headers = array(
"MIME-Version: 1.0",
"Content-Type: multipart/mixed; boundary=\"{$boundary}\"",
"From: my@from-email.dk"
);
$message = array(
"--{$boundary}",
"Content-Type: image/gif; name=\"mail-top-image.gif\"",
"Content-Transfer-Encoding: base64",
"Content-Disposition: inline; filename=\"mail-top-image.gif\"",
"",
chunk_split(base64_encode(file_get_contents("css/mail-top-image.gif"))),
"--{$boundary}",
"Content-Type: text/html; charset=UTF-8",
"Content-Transfer-Encoding: 7bit",
"",
$body,
"--{$boundary}--"
);
mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
}
In the message array, do I simply add another boundary for each image i want to insert in the $body, which contains the email message, and is where I insert the image?
"--{$boundary}",
"Content-Type: image/gif; name=\"img1.gif\"",
"Content-Transfer-Encoding: base64",
"Content-Disposition: inline; filename=\"img1.gif\"",
"",
chunk_split(base64_encode(file_get_contents("css/img1.gif"))),
"--{$boundary}",
"--{$boundary}",
"Content-Type: image/gif; name=\"img2.gif\"",
"Content-Transfer-Encoding: base64",
"Content-Disposition: inline; filename=\"img2.gif\"",
"",
chunk_split(base64_encode(file_get_contents("css/img2.gif"))),
"--{$boundary}",
"--{$boundary}",
"Content-Type: image/gif; name=\"img3.gif\"",
"Content-Transfer-Encoding: base64",
"Content-Disposition: inline; filename=\"img3.gif\"",
"",
chunk_split(base64_encode(file_get_contents("css/img3.gif"))),
"--{$boundary}",
And so on...And then call them by <img src tag wherever I need it in the email body??
Best, Klemme