HTML mail problem

Hi everyone.

I’m trying to put together gallery where you would choose a picture, fill in a form with some data (name, email, recipient and message) and receive somehow formatted e-card via html mail (I don’t want to send just a link).

[php]
$email_from = "[email protected]";
$email_subject = “E-card has just been sent by user $name”;
$ecard = "

[code]

$name has sent you this e-card

Send him one back



$message\n
$name

This email has been generated automatically using <b>
<a style=\"color:#C7EDF2\" href=\"http://domain.com\">
Send ecard service</a></b><br>
Reply to this message will be automatically redirected to sender's e-mail address 
($visitor_email)<br>

Some footer

[/code] ";

$to = “$rec_email”;

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=utf-8’ . “\r\n”;
//$boundary = uniqid(‘np’);
$headers .= “From: $email_from\n”;
$headers .= “Reply-To: $visitor_email\n”;
//$headers .= “Content-Type: multipart/alternative;boundary=” . $boundary . “\r\n”;
//$email_body .= “\r\n\r\n–” . $boundary . “\r\n”;
//$email_body .= “Content-type: text/html;charset=utf-8\r\n\r\n”;
$email_body = “$ecard”;
//$email_body .= “\r\n\r\n–” . $boundary . “\r\n”;
//$email_body .= “Content-type: text/plain;charset=utf-8\r\n\r\n”;
//$email_body .= “$plain”;
//$email_body .= “\r\n\r\n–” . $boundary . “–”;

mail($to, $email_subject, $email_body, $headers);[/php]

Everything seemed to work fine until I started testing different e-mail clients. In my webmail, the card arrived looking exactly as I intended. With other clients, the things weren’t so smooth.

In Gmail, I see just blank message - no pictures, no text, nothing…
In Outlook, I can see the pictures (correctly formatted) but I can’t see any text

I have commented out some other functionality which I thought might have been causing the problem but I still can’t display card correctly. Tried to search the web but didn’t get solution.

Anyone has an idea how to solve the problem?
Thanks in advance

UPDATE

In Yahoo, after allowing images, I saw nothing like in Gmail :frowning:

Never tried embedding images into mail but I came accross this:
http://www.phpeveryday.com/articles/PHP-Email-Using-Embedded-Images-in-HTML-Email-P113.html

[code]Well, to “embed” HTML into the body of a message, it is quite easy in PHP. You can use inline code as you posted, but, you have to mark it with a start and finish. To do this you use “<<<”. You pick a name or term that is not being used in your HTML, such as EOHTML for End Of HTML and start with “<<<EOHTML”. Everything after that will be placed into your string until it hits a “EOHTML;” in your code. Then, PHP continues.
So, here is your code with this added in:

[php]

$email_from = "[email protected]";
$email_subject = “E-card has just been sent by user $name”;
$ecard = <<<EOHTML

$name has sent you this e-card

Send him one back



$message\n
$name

This email has been generated automatically using <b>
<a style=\"color:#C7EDF2\" href=\"http://domain.com\">
Send ecard service</a></b><br>
Reply to this message will be automatically redirected to sender's e-mail address 
($visitor_email)<br>

Some footer

[/code] EOHTML;

$to = “$rec_email”;

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=utf-8’ . “\r\n”;
//$boundary = uniqid(‘np’);
$headers .= “From: $email_from\n”;
$headers .= “Reply-To: $visitor_email\n”;
//$headers .= “Content-Type: multipart/alternative;boundary=” . $boundary . “\r\n”;
//$email_body .= “\r\n\r\n–” . $boundary . “\r\n”;
//$email_body .= “Content-type: text/html;charset=utf-8\r\n\r\n”;
$email_body = “$ecard”;
//$email_body .= “\r\n\r\n–” . $boundary . “\r\n”;
//$email_body .= “Content-type: text/plain;charset=utf-8\r\n\r\n”;
//$email_body .= “$plain”;
//$email_body .= “\r\n\r\n–” . $boundary . “–”;

mail($to, $email_subject, $email_body, $headers);
[/php]
Not really sure about all that $boundary mess you have, but, I assume it is to store the picture.
Good luck, let us know if it works or if you need more help.

Thanks you both for suggestions. I can’t wait to “play” with my code. Let you know about the result

@Sabmin

Thanks for the tip, however, the comments under the article were mostly negative (seems that the code in the example did not work…), so I did not try this one.

@ErnieAlex

Thanks very much for the <<<EOHTML tip. I did not know and was using ", which was really annoying because I always forgot somewhere :frowning:

However this did not solve the issue. It’s just gonna make my work easier in the future.

Regarding your question about $boundaries, I tried to use them to add plain text version of the e-mail (although plain text of e-card seems stupid as my script does not generate browser version of the cards) because lacking of one was decreasing (or increasing? Nevertheless mail has been categorised as SPAM by gmail) my SPAM score :’(

The solution to the problem was (as usually) quite simple. It seems that most of mail clients can’t display HTML mails unless it’s (Heureka!!!) a table :o

Formatting whole HTML mail as a table solved the issue - all major clients (Gmail, Outlook, Yahoo, Lotus Notes - did not try any others) can display correctly (apart from [surprisingly] Outlook - what else could you expect from Microsoft product; however problem is just minor and I won’t chase solution… )

Thanks guys for help and for everyone who might have similar issue in future, here’s little example:

[php]$ecard = <<<EOHTML

New e-card from $name a:link { color: #59b8cc; } a:hover { color: #C7EDF2; }
           <tr>
            <td style="font-family: Helvetica, Arial, sans-serif; font-size: 11px; 
            color: #808080; padding-top: 15px;"> 
            If you think that this service might have been abused, please contact us at:<br>
          <a href="mailto: $admin"><b>
          $admin</b></a><br> 
      Send your own apocalypse e-cards, find out more about history, discuss interesting topics at 
      <b><a href="$webaddress">$webaddress</a></b><br>
      If this e-mail doesn't display correctly, please contact <a href="mailto:$admin">$admin</a>
      Please include information of your browser and mail clientr version<br><br>
      
      Copyright 2012 $webaddress<br></td>
    </tr>
$name just sent you this e-card

Send him one back
 
Ecard image

$message

$name

[/php]

Forgot to end

EOHTML;

Well, glad you sorted it out. And you are welcome for the <<<EOHTML trick. I have seen it written as <<<EOD for end-of-data, but, for HTML email, I like the eohtml verson… Anyway, glad you have succeeded!

CYA in the bitstream… LOL, that’s all this really is…

So thankful for people willing to help. Started coding in PHP 2 weeks ago, so many things are absolutely confusing for me and I’m still getting used to what I’m learning, correct syntax and everything.

I think that everyone who ever tried to code something can imagine how glad that it’s sorted out I am…

Sponsor our Newsletter | Privacy Policy | Terms of Service