Embedded Image in HTML email
Posted: Sat Jul 17, 2010 3:35 pm
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
the closest ive come to finding anything about converting it back to an image is
but i still dont know what to do with it.
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";
?>
Code: Select all
<?php
header ('Content-Type: image/jpg');
imagejpeg(imagecreatefromstring($file), null,100);
?>