Page 1 of 1

Embedded Image in HTML email

Posted: Sat Jul 17, 2010 3:35 pm
by Da_Elf
Im trying to do an emailer which would send a newsletter. I want to be able to replace the URL of the header logo with an embedded attached image so that people wont always have to click the "download from server" option when my emails come in. so far ive got the image into the email as a variable but dont know what to do with it in HTML. here is a simplified version

Code: Select all

<?php
$to = "email@emailaddress.com";
$subject = "a title";
$random_hash = md5(date('r', time()));
$headers = "From: some@addy.com\r\nReply-To: some@addy.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
$file =	file_get_contents("http://www.somewhere.com/sml_image.jpg");
ob_start(); 
?>
--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<table border="2" bordercolor="#000066" style="border-collapse:collapse" cellpadding="0" cellspacing="0" width="700" height="auto">
<tr>
 <td>****place the image here****</td>
</tr>
<tr>
  <td>***content***</td>
</tr>
</table>

--PHP-alt-<?php echo $random_hash; ?>--
<?
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent " : "Mail failed";
?>
the closest ive come to finding anything about converting it back to an image is

Code: Select all

<?php
header ('Content-Type: image/jpg'); 
imagejpeg(imagecreatefromstring($file), null,100);
?>
but i still dont know what to do with it.

Re: Embedded Image in HTML email

Posted: Sat Jul 17, 2010 5:22 pm
by Da_Elf
never mind. i guess its just best to put it in as a direct link which means the receiver will have to click to download the online image

Re: Embedded Image in HTML email

Posted: Sat Jul 17, 2010 6:23 pm
by adampalmer
You can do it with PHPMailer:

Code: Select all

$mail->AddEmbeddedImage()