3

In PHP, I'm trying to send emails in HTML format. So far I have this

            $subject = "Password Reminder";
            $message = "Your password is <b>{$password}</b>.<br/><br/><br/><br/>me";
            $message = wordwrap($message, 70, "\r\n");
            $headers = 'From: me@gmail.com' . '\r\n' .
                'Reply-To: me@gmail.com' . '\r\n' .
                'X-Mailer: PHP/' . phpversion() . '\r\n' .
                'MIME-Version: 1.0\r\n' . '\r\n' .
                'Content-Type: text/html; charset=ISO-8859-1\r\n';

            mail($email, $subject, $message, $headers);

I followed this guide: http://css-tricks.com/sending-nice-html-email-with-php/

But when I get the email, it shows with the tags, I want it to interpret the tags into html.

Does anyone know whats wrong?

Thanks.

omega
  • 40,311
  • 81
  • 251
  • 474
  • I hate to rain on somebody's parade, but I've visited that site (css tricks) countless times to see that most or all information on that site contained errors. When in doubt, **always refer to the actual (PHP) manuals** --- [`Consult the manual on both mail() and header() functions on PHP.net`](http://php.net/manual/en/function.mail.php) – Funk Forty Niner Dec 21 '13 at 20:11
  • To add from some recently-learned information, take out `'X-Mailer: PHP/' . phpversion()` as you're giving potential hackers information about your server and is a security hole. This, comes from a reliable source here on SO. – Funk Forty Niner Dec 21 '13 at 20:13

1 Answers1

9

this is most likely the problem: 'MIME-Version: 1.0\r\n' . '\r\n' .

after two endlines the headers end and the body starts. So your content-type declaration of text/html is being parsed as message body, while it belongs to headers.

remove one endline and it should work:

'MIME-Version: 1.0\r\n'

also I noticed you use single quotes for \r\n. You should use double quotes or else they will be escaped. You need them to be parsed.

 'From: me@gmail.com' . "\r\n" .
                'Reply-To: me@gmail.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion() . "\r\n" .
                'Content-Type: text/html; charset=ISO-8859-1'."\r\n".
                'MIME-Version: 1.0'."\r\n\r\n";
klarki
  • 915
  • 4
  • 13