Send HTML emails with images from PHP

Posted on 2009-02-18
Last Modified: 2012-05-06
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

Question by:satmanuk
    LVL 9

    Accepted Solution

    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!
    LVL 1

    Expert Comment

    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

    LVL 1

    Author Comment



    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now