Adriano Varoli Piazza
Adriano Varoli Piazza

Reputation: 7429

Outlook 2007 receives html mail as source with headers, others MUAs work fine. Why?

I have a couple of simple forms that send an html-only email. Most clients (Gmail, Lotus Notes 8, hotmail/live, windows live mail, outlook express) receive the emails just fine, but Outlook 2007 does not.

The code looks like this:

$data="
            <html>
                <body>
                    <strong><u>$sub</u></strong><br><br>
                    <strong>Name:</strong> {$_POST["nombre"]}<br><br>
                    <strong>Phone:</strong>{$_POST["telefono"]}<br><br>
                    <strong>Email:</strong> {$_POST["email"]}<br><br>
            <strong>Subject:</strong> {$_POST["asunto"]}<br><br>
                    <strong>Question:</strong> {$_POST["consulta"]}</strong>
                </body>
            </html>";
            $header = "Reply-To: $from\r\n";
            $header .= "From: \"".$_POST["nombre"]."\" <$from>\r\n";
            $header .= "MIME-Version: 1.0\r\n";
            $header .= "Content-Type: text/html; charset=iso-8859-1\r\n";

            $enviado = mail($destino,$sub,$data,$header);

($from is the only part of the message validated)

The message received by the customer looks like this:

Content-Type: text/html; charset=iso-8859-1
From: Consulta de "Boss" <[email protected]>
Reply-To: [email protected]
X-Mailer: PHP/

<strong><u>Solicitud de envío de recetas -
CLIENT</u></strong><br><br><strong>Nombre y Apellido:</strong>
Boss<br><br><strong>Email:</strong>
[email protected]<br><br><br>

Any ideas?

Upvotes: 3

Views: 10151

Answers (8)

Morgan
Morgan

Reputation: 31

I encountered the same problem with Outlook 2007.

The answer is simple : replace \r\n by \n

Upvotes: 3

Benoit
Benoit

Reputation: 3598

Have you tried sending multipart email, when doing this we never had issues with outlook 2k3 and 2k7 (excepts poor HTML rendering)

<?php
$header = "From: Sender <[email protected]>\r\n";
$header .= "Reply-to: Sender <[email protected]>\r\n";
$header .= "X-Mailer: Our Php\r\n";

$boundary = "==String_Boundary_x" .md5(time()). "x\r\n";
$boundary2 = "==String_Boundary2_y" .md5(time()). "y\r\n";

$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/related;\r\n";
$header .= " type="multipart/alternative";\r\n";
$header .= " boundary="$boundary";\r\n";

$message = "If you read this, your email client doesn't support MIME\r\n";

$message .= "--$boundary\r\n";
$message .= "Content-Type: multipart/alternative;\r\n";
$message .= " boundary="$boundary2";\r\n";

$message .= "--$boundary2\r\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "Alternative message in plain text format.\r\n";

$message .= "--$boundary2\r\n";
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "<html><body><p>HTML formatted message</p></body></html>";

You can replace boundaries with whatever you want, but they must be unique.

For more powerful and flexible email sending in php I suggest to use SwiftMailer

EDIT : as Outlook 2007 has a really dumb HTML renderer, you can also try fixing your markup, there is a </font> never opened in your example, dunno if it's the real mail or a typo in question.

Upvotes: 8

Jim
Jim

Reputation: 41

I had a very similar problem, try removing the /r from your returns and use only /n. Outlook andd hotmail have trouble with /r/n.

Upvotes: 4

Michael Konečn&#253;
Michael Konečn&#253;

Reputation: 1764

I confirm the experience with Exchange janmoesen has shared. Had to change CRLF in headers to just LF, then it started working.

(Thank you Microsoft, once again, for having me work 40% time extra.

Also a real thank you to janmoesen for pointing this! This search is over.)

Upvotes: 3

janmoesen
janmoesen

Reputation: 8020

I have had trouble with Exchange (not just Outlook) and CRLF in headers with similar results. Basically, we were sending mails (using PHP on Debian with Postfix) with CRLF-separated headers, which would get mangled in Exchange upon arrival. When I changed those \r\n to simply \n, the problem was gone. ("RFCs be damned!", eh?)

YMMV, obviously, since it is not clear whether your other mail clients connect to the same server as Outlook, or use separate servers altogether.

Upvotes: 2

dpb
dpb

Reputation: 1205

I have always had better luck with MIME encoded HTML mails. Even if there is just one part, I typically use multipart/mixed and explicitly set the content type (text/html). I'm not very familiar with PHP, but the PEAR::Mail_Mime package looks like a candidate.

Outlook shouldn't have a problem handling it. (emphisis on shouldn't).

Upvotes: 1

John Conde
John Conde

Reputation: 219844

If the message is in HTML you need to identify it as such:

$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";

Upvotes: 1

Related Questions