1

I'm sending a php html mail with this code:

$msg = "<p>Beste,</p> <p>Sorry, maar momenteel zijn deze CD uitverkocht. Daarom is uw order met ordernummer 15 opgesplits. Uw eerste order ( 15 ) wordt volgens planning geleverd.</p> <p>Het order nummer voor uw overige producten die niet geleverd kunnen worden is: 16. Deze hopen we zo spoedig mogelijk te leveren.</p> <p>&nbsp;</p> <p>Sorry voor het ongemak.</p> <p>Met Vriendelijke Groet,<br /> Wij</p> ";

$message  = '<html dir="ltr" lang="en">' . PHP_EOL;
$message .= '<head>' . PHP_EOL;
$message .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . PHP_EOL;
$message .= '<title>Er zijn wijzigingen aangebracht aan uw order</title>' . PHP_EOL;
$message .= '</head>' . PHP_EOL;
$message .= '<body style="padding:0;margin:0;">' . $msg . '</body>' . PHP_EOL;
$message .= '</html>' . PHP_EOL;

$message = str_replace(array(chr(3)), '', $message);

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: ons <[email protected]>' . "\r\n";

mail($email, 'Er zijn wijzigingen aangebracht aan uw order', $message, $headers);

But the problem is that i'm getting the email as plain text (I can see the HTML tags). So what is the problem? As far as I know's are the headers properly set.

6
  • try <br> instead of PHP_EOL Commented Sep 11, 2013 at 10:31
  • I just tried your code out, and received the email in GMail it comes out fine, not html tags seen... What email client are you seeing the tags in? Commented Sep 11, 2013 at 10:34
  • @Deepanshu, that didn't work. Commented Sep 11, 2013 at 10:37
  • @Joeme, i use webmail ( telfort ) and Thunderbird. Both show the message wrong. I will try it with gmail now... Commented Sep 11, 2013 at 10:38
  • @Joeme, even in GMail it isn't working :S Commented Sep 11, 2013 at 10:39

1 Answer 1

3

Well, the answer is very simple.

After i looked at the source in gmail, i could see all these things: &lt;p&gt;.

The problem was that the text was comming from an WYSIWYG editor, so all the entitys where encoded.

So after added this line, everything worked fine:

$message = html_entity_decode($message);

I hope that i could help somebody with this self answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.