Chud37
Chud37

Reputation: 5007

php Mail() and Outlook

I have the following code:

    $subject = "Test Email";
    $from = "[email protected]";
    ini_set("sendmail_from", $from);
$message = "<html><body bgcolor=\"#DCEEFC\"> 
                Hello<br><br>
                This is a <b>test</b> email.
                <br><br><hr>
                <a href=\"\">Click Here</a>     
                <br><br><hr>
                <br><br>
                Thank you for your time,<br><br>
            </body></html>";

    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html\r\n"; 
    $headers .= "From: " . $from . "\r\n";
    mail($mail, $subject, $message, $headers);

However, when I send the email to myself, I see all the code in Outlook. If i send it to someone else, They see the HTML. If i send it to my hotmail, they see the HTML.

Is this a problem with my outlook (2007), if so, what is it, or can I do something in the email to guarantee it being displayed properly?

Please help!

Upvotes: 6

Views: 17221

Answers (3)

Chud37
Chud37

Reputation: 5007

I found the problem:

HTML Email not displaying correctly for Godaddy web based mail

Changed:

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n"; 
$headers .= "From: " . $from . "\r\n";

to:

$headers  = "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-Type: text/html; charset=ISO-8859-1" . PHP_EOL;
$headers .= "From: Site<$from>" . PHP_EOL;

Thanks for all your help guys! :)

Upvotes: 8

MiDo
MiDo

Reputation: 1057

Try to reorder the header. I remember having the same problem a while ago and it worked after I used the following headers:

    $headers = "From: " .$from. "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
    $headers .= "Content-Transfer-Encoding: 8bit\r\n";

I would recommend though to use a ready-to-go php mailer class - it makes life much easier.

Upvotes: 2

Fluffeh
Fluffeh

Reputation: 33512

Sounds like you have your outlook set to display messages in plain text, no matter the format they are sent in.

Go into your outlook prefs and change it to view the messages in the format that they arrive in.

Upvotes: 1

Related Questions