Ok, I have tried every pssible way to make this possible but it looks like im running in to cercles...

My script simply doesnt want to send embaded logo... It wants to send it as an image like <img src="http'//..." /> but than i have problem with viewing the email because client has to download image every time (Outlook 2010/2013) For me it wouldnt be a problem but some clients find it anoying... Can enyone help me? This is my code

global $dal;

$dal_TableName = $dal->Table("table");


foreach(@$keys as $keyblock)





$where = KeyWhere($arr2);
$rstmp = $dal_TableName->Query($where,"");
$datatmp=db_fetch_array($rstmp );

$body .= "
<style type='text/css'>
table.email {
    border-width: 1px;
    border-spacing: 2px;
    border-style: outset;
    border-color: #cccccc;
    border-collapse: collapse;
    background-color: white;

table.email td {
    border-width: 1px;
    padding: 5px;
    border-style: inset;
    border-color: #cccccc;
    background-color: white;
    -moz-border-radius: ;

<table ><tbody><tr><td>
<img src='http://domain.com/images/logo.gif' width='205' />




// send the email

$email= "";
$from = "";

$arr = runner_mail(array('to' => $email, 'from' => $from, 'subject' => $subject, 'htmlbody' => $body, 'charset' => 'UTF-8')); 

$result["txt"] = "Email is sent.";

// if error happened print a message on the web page

if (!$arr["mailed"])


  $errmsg = "Error happened: <br>";

  $errmsg.= "File: " . $arr["errors"][0]["file"] . "<br>";

  $errmsg.= "Line: " . $arr["errors"][0]["line"] . "<br>";

  $errmsg.= "Description: " . $arr["errors"][0]["description"] . "<br>";

  $result["txt"] = $errmsg;


Any ideas would be helpful.. I found soo manny tutorials and info how it should be done but none of the things work.. Tried base64 encode and directly placed the encoded image but no luck...

This code however, works...

$to =   '';
$subject =  'PHP Mail Attachment Test';
$bound_text =   "test";
$bound =    "--".$bound_text."\r\n";
$bound_last =   "--".$bound_text."--\r\n";

$headers =  "From: admin@server.com\r\n";
$headers .=     "MIME-Version: 1.0\r\n"
    ."Content-Type: multipart/mixed; boundary=\"$bound_text\"";

$body .=    "If you can see this MIME than your client doesn't accept MIME types!\r\n"

$body .=    "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
    ."Content-Transfer-Encoding: 7bit\r\n\r\n"
    ."<img src=\logo.gif\" />\r\n"

$file =     file_get_contents("http://domain.com/logo.gif");

$body .= "Content-Type: image/gif; name=\"logo.gif\"\r\n"
    ."Content-Transfer-Encoding: base64\r\n"

if(mail($to, $subject, $body, $headers))
     echo 'MAIL SENT';
} else {
     echo 'MAIL FAILED';

but i can nooot get first one to work... if i try to mix it together i get whole email encoded...

Anny ideas would help me allot!

Thank you!

4 Years
Discussion Span
Last Post by paulkd

i didnt check the whole code but you can try the following:

Content-Type: multipart/mixed

change to:
Content-Type: text/html


As far as I can tell (from a quick glance) your MIME encoding seems OK

However, you need to specify the image as inline, or it will show up as an attachment.

Content-Disposition: inline; filename=logo.gif

You also need to specify an ID for reference within the email content. (this is arbitrary but I find it useful to use the filename for clarity sake)

Content-ID: logo.gif

Then in the message body the image source references the content ID of the attached MIME segment.

<img src="cid:logo.gif" />

I think that is all you will need to modify.

edit: additional note You may want to use a longer string for your boundary, typically a randomly denerated md5 hash or similar is used, though again strictly speaking this is arbitrary (you just don't want it to be something that may occur accidentally within message content.)

Also, having your $bound variable including the line breaks will mean that your MIME boundary definition Content-Type: multipart/mixed; boundary=\"$bound_text\"" will push the closing quote mark onto the next line - might be advisable to add the line breaks separately.

Edited by |-|x: additional note



Thank you all for advices. The second piece of code works fine. My problem is that i have to make first piece to work but i dont know how to combine it with second which works... I tried eeverything i could possibly find on the web but no luck... best result was that i have sent encoded message hahaha So if anyone could suggest what to modify in first part to make it work i would be really greatfull...


Tried to put it but it still not working... I have to download image...


encode the image as base64, then WRITE/echo the encoded image into the email. do not refer to a location on the server

open a received email from someone else
EDIT: with an image
in a text editor and look at the source, the process will become easier to concept
and you can write the logo into the php script

Edited by almostbob


Ok... I have added it like this

$img = "<img alt='' src='data:image/png;base64,iVBORw0KGgP/8/IiWrM3S3DBGbn6Mpfvh4qiywllqi...' />";

and called it like this <table><tbody><tr><td>" . $img . "</td><td> but there is no image and it is not avalable for download.



I haven't thoroughly read this thread and the code, but just want to point out that you may need to click something in your email client to allow images to display.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.