[thelist] Embedding images in email

R.Livsey R.Livsey at cache-22.co.uk
Tue Jul 10 12:18:37 CDT 2001


Im having problems trying to get an image sent embedded in an email.


here is the code I am using.
it is at www.tickle.co.uk/testarea/test_scripts/test_mail.php


<?
// steup vars
$to = "r_livsey at yahoo.co.uk"; 

$subj = "is it working yet"; 

$userfile = "/sites/tickle/testarea/test_scripts/image.gif";
$mail_boundary = md5(uniqid(time())); 


// open the image file and encode it etc..
$fp = fopen($userfile, "r"); 
$file = fread($fp, filesize($userfile)); 
$file = chunk_split(base64_encode($file));


// do the headers and body
$mail_headers = "MIME-Version: 1.0\r\n"; 
$mail_headers .= "multipart/related; boundary=\"$mail_boundary\";
type=Text/HTML\r\n\r\n"; 

$body = "--$mail_boundary\r\n"; 
$body .= "Content-type: text/html; charset=US-ASCII\r\n"; 
$body .= "some text here followed by an image <IMG
SRC=\"cid:img1*r_livsey at yahoo.co.uk\">\r\n\r\n";
$body .= "--$mail_boundary\r\n"; 
$body .= "Content-ID: img1*r_livsey at yahoo.co.uk\r\n";
$body .= "Content-type: IMAGE/GIF;\r\n"; 
$body .= "Content-Transfer-Encoding: BASE64\r\n\r\n";
$body .= $file . "\r\n\r\n"; 
$body .= "--$mail_boundary--"; 

// send the mail
mail($to,$subj,$body,$mail_headers); 

// debug : what was sent?
echo "$mail_headers$mail_body";
?>


I get the email but it just contains all the code (Ie it doesnt show the
image just all the mime code etc...).

Any ideas? Cheers.


R.Livsey
Lead Programmer for the Tickle Group
Freelance work always welcome
[ PHP | Perl | mySQL | Java ]
work 		: www.tickle.co.uk
personal 	: www.cache-22.co.uk
e : R.Livsey at cache-22.co.uk
m : +447764 685 701
i : 37530949 
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.262 / Virus Database: 132 - Release Date: 12/06/2001






More information about the thelist mailing list