Embed images in php mail function

Hi,

Does someone have a working script to embed images inside
a html email generated from php.

This is my function that currently works but It keeps trying to download the image live if i am offline.It needs to be embedded so you can still see it while offline.

$HTML .= "<img src=\“http://www.mysite.com/image.jpg\\”>\r
";
$HTML .= "rest of the content here\r
";
$HTML .= "rest of the content here\r
";

$to = myself@mysite.com;
$from = “info@mysite.com”;
$rp = ‘me@mysite.com’;
$subject = “subject of the mail”;

$headers = “From: Website<” . $from . “>”;
$headers .= "
MIME-Version: 1.0
" . "Content-Type: text/html;
";

$headers .= "Return-Path: $rp \r
";
$message = $HTML;
$ok = @mail($to, $subject, $message, $headers);

Can someone chage this for me so that the img
<img src=\“http://www.mysite.com/image.jpg\\”>

gets embedded in the mail.

Thanks a milion

set image like a coockie so it will be stored into temp internet folder!

Yo

set image like a coockie so it will be stored into temp internet folder!

Maybe you could post some script that you have working ?

Anyways, not sure exactly what your problem is, I suspect that your not setting the correct MIME TYPE, though to save yourself a lot of hassle, have you heard about PHP Mailer ?

Features

Does the job for you, and saves you a lot of time and hassle. You can also find examples and the documentation at the same link :slight_smile:

http://phpmailer.sourceforge.net/

I did post a working sample of an html mail.

I did have a look at the php mailer and I’m a bit blond trying to implement the class :slight_smile:

I’m just looking for a standard html mail function with embeded images
without using a database like the sample in the phpmailer

what you could do is set the body of the message as a variable ie:


 /* message */
$message = '
<html>
<head>
<title>email message</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td align="left" background="http://yoursite.com/images/generic_images/emailbgtop.jpg"><img src="http://yoursite.com/images/generic_images/emailheader.jpg" width="413" height="127"></td>
  </tr>
  <tr>
    <td align="center"><font face="Tahoma, Verdana, Arial" font size="2"><br>
      message text::message text::message text::message text::message text::message text::message text
    </font></td>
  </tr>
  <tr bgcolor="#ECECEC">
    <td align="center" bgcolor="#FFFFFF"><strong><font face="Tahoma, Verdana, Arial" font size="2" color="#0DC005">Thank You! :) </font></strong></td> </tr>
  <tr bgcolor="#ECECEC">
    <td background="http://yoursite.com/images/generic_images/emailbgbottom.jpg"><img src="http://yoursite.com/images/generic_images/emailbgbottom.jpg" width="166" height="77"></td>
  </tr>
</table>

</body>
</html>

';

The advantage of doing the message like this is that you can design the page seperately and then drop it in between the quotes.

You then need to set the headers. So the whole code looks like:

$to  = "$_POST[name] <$_POST[email]>" . ", " ; // note the comma

/* subject */
$subject = "Advert Placement on http://yoursite.com";

/* message */
<html>
<head>
<title>email message</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td align="left" background="http://yoursite.com/images/generic_images/emailbgtop.jpg"><img src="http://yoursite.com/images/generic_images/emailheader.jpg" width="413" height="127"></td>
  </tr>
  <tr>
    <td align="center"><font face="Tahoma, Verdana, Arial" font size="2"><br>
      message text::message text::message text::message text::message text::message text::message text
    </font></td>
  </tr>
  <tr bgcolor="#ECECEC">
    <td align="center" bgcolor="#FFFFFF"><strong><font face="Tahoma, Verdana, Arial" font size="2" color="#0DC005">Thank You! :) </font></strong></td> </tr>
  <tr bgcolor="#ECECEC">
    <td background="http://yoursite.com/images/generic_images/emailbgbottom.jpg"><img src="http://yoursite.com/images/generic_images/emailbgbottom.jpg" width="166" height="77"></td>
  </tr>
</table>

</body>
</html>

';
/* To send HTML mail */
$headers  = "MIME-Version: 1.0\\r\
";
$headers .= "Content-type: text/html; charset=iso-8859-1\\r\
";

/* additional headers */
$headers .= "From: YoursiteAdmin <admin@yoursite.com>\\r\
";

/* and now mail it */
mail($to, $subject, $message, $headers);


Hope this helps

SpikeZ

tomcat

If you’re trying to implement the mime-mailer, first send yourself a message with images and view its source. Second, read http://www.faqs.org/rfcs/rfc1521.html to find out what do “multipart/mixed” and “content-id” mean.
Then… implement the mailer. There is nothing magical about this.