开发者

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

开发者 https://www.devze.com 2022-12-18 02:35 出处:网络
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

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开发者_Python百科";
            $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" <boss@myfirm.com>
Reply-To: boss@myfirm.com
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>
boss@myfirm.com<br><br><br>

Any ideas?


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 <sen...@domain.org>\r\n";
$header .= "Reply-to: Sender <blabla...@domain.net>\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.


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.


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


I encountered the same problem with Outlook 2007.

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


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.


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

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


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.

  • http://pear.php.net/package/Mail_Mime

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号