0

I have this function, which sends an email to the user and confirms an order.

I cant figure out why I cant get to display the image IN the email, at the very top.

I have tried with:

"Content-Disposition: attachment; filename=\"mail-top-img.gif\""

And

"Content-Disposition: inline; filename=\"mail-top-img.gif\""

Both sends the mail as an attachment to the message.

This is the function where something needs to be changed for the image to appear in the message body:

<?php
 function mail_img_kvittering($to, $from, $subject, $body)
 {
 $boundary = md5(rand());

 $headers = array(
     "MIME-Version: 1.0",
     "Content-Type: multipart/mixed; boundary=\"{$boundary}\"",
     "From: {$from}"
     );    

 $message = array(
     "--{$boundary}",

     "Content-Type: image/gif; name=\"mail-top-img.gif\"",
     "Content-Transfer-Encoding: base64",
     "Content-Disposition: attachment; filename=\"mail-top-img.gif\"",
     "",
     chunk_split(base64_encode(file_get_contents("css/mail-top-img.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));
 }
 ?>
 `

Edited by happygeek: fixed formatting

3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by klemme
0

I have this function, which sends an email to the user and confirms an order.

I cant figure out why I cant get to display the image IN the email, at the very top.

I have tried with:

"Content-Disposition: attachment; filename=\"mail-top-img.gif\""

And

"Content-Disposition: inline; filename=\"mail-top-img.gif\""

Both sends the mail as an attachment to the message.

This is the function where something needs to be changed for the image to appear in the message body:

function mail_img_kvittering($to, $from, $subject, $body)
{
$boundary = md5(rand());

$headers = array(
"MIME-Version: 1.0",
"Content-Type: multipart/mixed; boundary=\"{$boundary}\"",
"From: {$from}"
);    

$message = array(
"--{$boundary}",        
"Content-Type: image/gif; name=\"mail-top-img.gif\"",
"Content-Transfer-Encoding: base64",
"Content-Disposition: inline; filename=\"mail-top-img.gif\"",
"",
chunk_split(base64_encode(file_get_contents("css/mail-top-img.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));
}
0

The $body must contain a "webpage" displaying the image, complete with <html> and <body> tags.
for the image use a remote link: www.yourserver.com/css/mail-top-img.gif

0

Thank you for the answer/solution pzuurveen!

It worked fine, after inserting tags and actually calling the image..

Thank you!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.