views:

715

answers:

5

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?

+1  A: 

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

$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
John Conde
Argh! copied and pasted from the wrong version (I was editing the code to plaintext to get by). It did say 'text/html' in the real code. I corrected the question, thank you.
Adriano Varoli Piazza
A: 

There are lots of problems with HTML email in Outlook 2007.
http://www.molly.com/2007/01/18/what-happened-with-html-and-css-in-outlook-2007/

http://fixoutlook.org/

http://www.developertutorials.com/tutorials/html/microsoft-complicates-html-emails-with-outlook-2007-070130/page1.html

and so on.

echo
Ok, but those problems are (as far as I read) of the 'my layout is not showing correctly' kind, not of the 'crap, the headers of the message are displayed and I get raw html' kind. Or am I wrong? The layout for the message in question has nothing complicated.
Adriano Varoli Piazza
I imagine it's related. I fought with this a few years back and gave up. HTML email is evil anyway, and outlook is trying its best to deal with the evils of HTML email by fiddling with your content.
echo
Oh, sure. I'm phoning the customer right now and telling her 'you know what? HTML email is evil. Justin said so'.
Adriano Varoli Piazza
I feel your frustration. It's the truth though....
echo
I'm not frustrated. I'm curious. I want to know why. You're the one that said 'I gave up a few years back'. And your 'html email is evil' point is ridiculous. Leave the term to something truly worthy of it. Like Cobol.
Adriano Varoli Piazza
http://www.asciiribbon.org/
echo
Look, I'm not trying to get into an argument here, I'm just stating what I believe to be true. I'm not the one who decided HTML email is a bad idea. There's information all over the web that says the same thing, if you care to do a bit of googling. It's one of those user-friendly "features" that turned out to be a huge security nightmare, and there are reasons that MS Outlook doesn't just display HTML email as-is.
echo
please, reread the question and my first comment to this answer.
Adriano Varoli Piazza
Outlook using MS Word to render HTML formatted email won't be the problem here. The problem here is extracting the message body from the email, which has nothing to do with what happens to the body afterwards.
David Dorward
+1  A: 

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).

dpb
+1  A: 

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.

janmoesen
+1  A: 

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 bondaries with wathever 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 never opened in your exemple, dunno if it's the real mail or a typo in question.

Benoit
yes, the font tag is a typo, thanks.
Adriano Varoli Piazza
Thank you. This was clear and helpful.
Adriano Varoli Piazza
glad it helped you
Benoit