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));
 }
 ?>
 `

Recommended Answers

All 5 Replies

How do I post code in this editor...??????

Indent with 4 spaces, or start and end with ~~~ (needs an empty line before it.

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));
}

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

Thank you for the answer/solution pzuurveen!

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

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.