PHPMailer and Inline Images

16:51.57 - Thursday 30th September 2004   (Link to This Entry)


Been trying to find out how to send inline image attachments in a HTML email this afternoon, and my plodding eventually lead me to try PHPMailer after mucking about with some other class thing that didn't do as I wanted.

After much stumbling about (a lot, considering I only wanted to do one thing) I came up with this:

<?
  include('class.phpmailer.php');
	
  $mail=new phpmailer();  
  $mail->From    ='sender@domain.com';
  $mail->FromName='D';
  $mail->Host    ='localhost';
  $mail->Subject ='Testy testy test - YAY!';	
  $mail->AddAddress('recipient@domain.com');
	
  $mail->IsHTML(true);
  $mail->AddEmbeddedImage('bean.gif','beanimage','bean.gif');
  $mail->Body    ='<HTML><BODY><IMG SRC="cid:beanimage"></BODY></HTML>';
	
  $mail->Mailer  ='mail';
  $mail->Send();
?>
Which seemed to do the job nicely. The end result is an email that contains an image but [a] doesn't download it from a remote server and [b] doesn't have an attachment. All this just to send out some spam promotional material!

Comments on this entry:
This is a very practical and useful example I have found. Thank you so much.
Severin

[ 0 comments pending ]