Link to home
Start Free TrialLog in
Avatar of satmanuk
satmanukFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Mahdii7
Mahdii7
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of generationg
generationg

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

Avatar of satmanuk

ASKER

Excellent

Thanks!