Send HTML emails with images from PHP

Hi there,

I am looking for a way to send HTML emails using PHP. i have managed to source info on the basics but wondered if anyone knew how i imbed images into my html?

i found what i want but i think i have to install something server side and im not sure if my hosting will do that or not. The site i found was
http://www.phpguru.org/downloads/html.mime.mail/

Does anyone know this class and do you know if somethig has to be installed? i think i do as i was reading this tutorial and it says to install something to the server.
http://ghostwire.com/archives/phpobject/000051.html

Hope you can help

Thanks
LVL 1
satmanukAsked:
Who is Participating?
 
Mahdii7Connect With a Mentor Commented:
This is actually very simple. You need to have absolute paths in the email for images (ie. http://www.domain.com/images/image1.jpg instead of images/image1.jpg), and there are many good classes for sending HTML mail via PHP that require no server-side modifications.

I highly recommend PHPMailer, a class that I use frequently in my projects requiring MIME/HTML mail.

http://phpmailer.codeworxtech.com/

They provide native support for HTML mail.

Good luck!
0
 
generationgCommented:
Either use PHPMailer as mentioned or you can set your headers to HTML if you want to use the mail() class in PHP.
I've added the code to send out a multi part e-mail, so it'll include HTML and plain text. Something that PHPMailer won't do.

$htmlVer is your HTML version of the e-mail, with full HTML code including full paths to images.
$textVer is your plain text version, nothing but text.
//Additional headers
$headers = 'From: you@yourdomain.com' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"==MB_$random_hash\"\r\n"; 
 
//E-mail code
 $strCode="This is a multi-part message in MIME format.\n\n";
    $strCode.="--==MB_$random_hash\n";  
    $strCode.="Content-Type: text/plain; charset=\"iso-8859-1\"\n"; 
    $strCode.="Content-Transfer-Encoding: 7bit\n";
    $strCode.=$textVer;
    $strCode.="\n";
    $strCode.="--==MB_$random_hash\n";
    $strCode.="Content-Type: text/html; charset=\"iso-8859-1\" \n";
    $strCode.="Content-Transfer-Encoding: 7bit\n";
    $strCode.=$htmlVer;
    $strCode.="\n";
    $strCode.="--==MB_$random_hash--";
 
if(mail($to, $subject, $strCode, $headers))
{ echo("Done"); }
else
{ echo("Something went wrong"); }

Open in new window

0
 
satmanukAuthor Commented:
Excellent

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.