PHP - mail() with inline image?

Posted on 2004-11-29
Last Modified: 2008-02-26

I am creating a webshop. and now i am going to send the email with the order.
BUT... it needs to be in HTML (no problem), and with inline images (you attach an image to the mail and this is displayed in the mail)

Does anybody know how this can be done??

the script i have:


      list($name, $adres, $zipcode, $location, $telephone, $email, $paymethod, $agree) = split("!", $_COOKIE[COOKIE]);
      $producten_ids = substr($_SESSION['producten_shop'], 0, -1);
      $producten_ids = explode("!", $producten_ids);
$htmlversion = ("
Your details:<br>
Naam:                  " . $name. "<br>
Adres:                  " . $adres . "<br>
Postcode:            " . $zipcode. "<br>
Plaats:                  " . $location. "<br>
Telefoon:            " . $telephone. "<br>
Email:                  " . $email . "<br>
Betaalmethode:            " . $paymethod. "<br>
Our details:<br>
Naam:                  " . NAME. "<br>
Adres:                  " . ADRES . "<br>
Postcode:            " . ZIPCODE. "<br>
Plaats:                  " . LOCATION. "<br>
Telefoon:            " . TELEPHONE. "<br>
Email:                  " . EMAIL . "<br>
Your order::<br>

$arraylengte = count($producten_ids);

for($i=0; $i < $arraylengte; $i++){
      $htmlversion .= "product id: " . $producten_ids[$i] . "<br>";

$headers = "From:\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$boundary = uniqid("SHOP");
$headers .= "Content-Type: multipart/alternative" .
   "; boundary = $boundary\r\n\r\n";
$headers .= "This is a MIME encoded message.\r\n\r\n";
$headers .= "--$boundary\r\n" .
   "Content-Type: text/html; charset=ISO-8859-1\r\n" .
   "Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode($htmlversion));
if(mail("", "Thanks for your order!", "", $headers)){
      $message = "goed";
} else {
      $message = "fout";


$_COOKIE[COOKIE] and $_SESSION['producten_shop'] are set in the previous page and contain the account details and products ordered. (all works perfect)

So can anybody help me with the inline images??

thanks, Mike
Question by:php-webdesign
    LVL 48

    Accepted Solution

    Use for this.

    It allows easy attachment of inline-images
    For a example see

    So you don't need to reinvent the wheel
    LVL 5

    Author Comment

    thank you m8!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now