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

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.

Hope you can help

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. 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.

They provide native support for HTML mail.

Good luck!
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:' . "\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.="Content-Type: text/plain; charset=\"iso-8859-1\"\n"; 
    $strCode.="Content-Transfer-Encoding: 7bit\n";
    $strCode.="Content-Type: text/html; charset=\"iso-8859-1\" \n";
    $strCode.="Content-Transfer-Encoding: 7bit\n";
if(mail($to, $subject, $strCode, $headers))
{ echo("Done"); }
{ echo("Something went wrong"); }

Open in new window

satmanukAuthor Commented:

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.