I have this code to send an email via PHP:
// Prepare email.
$headers = "From: Mi9 Vault <info@mi9vault.com.au>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1";
$msg = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/edm/confirmation.html');
$msg = str_replace('{first_name}', $contact["First Name"], $msg);
// Send email
mail($contact["Email Address"], "Your Mi9 Registration is Confirmed", $msg, $headers);
confirmation.html is a HTML email that we’ve set up.
I’ve never had any trouble with the above PHP code for sending emails before, however all I can seem to get back is an email containing all of the HTML rather than an actual HTML formatted email.
Basically I get an email with this as the content:
MIME-Version: 1.0
Content-type: text/html; charset=ISO-8859-1
Message-Id: <20120418080325.C643B407EF@ds3219.dreamservers.com>
Date: Wed, 18 Apr 2012 01:03:25 -0700 (PDT)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
.....
I have the same PHP code on another website with the same host and it works fine…
It seems from that somehow there are extra line breaks between each two lines of your headers. How it manages to happen, I’m not sure, as your code doesn’t put them there. It’s possible that the receiving mail server is messed up somehow and interprets
\r\nas two line breaks instead of one. To start with, I would remove\rleaving only\nin and see what happens. I know this is not proper per RFC – but start with that.To make you feel better, I am using a very similar code – and the email gets delivered correctly.