代码之家  ›  专栏  ›  技术社区  ›  Adriano Varoli Piazza

Outlook2007将HTML邮件作为带有标题的源代码接收,其他MUA工作正常。为什么?

  •  3
  • Adriano Varoli Piazza  · 技术社区  · 15 年前

    我有几个简单的表单,它们只发送HTML格式的电子邮件。大多数客户机(gmail、Lotus Notes 8、hotmail/live、Windows Live Mail、Outlook Express)都可以接收到这些电子邮件,但Outlook 2007没有。

    代码如下:

    $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 是验证消息的唯一部分)

    客户收到的消息如下:

    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>
    

    有什么想法吗?

    8 回复  |  直到 12 年前
        1
  •  8
  •   tw16    13 年前

    您是否尝试过发送多部分电子邮件,在执行此操作时,Outlook 2K3和2K7从未出现问题(HTML呈现不佳除外)

    <?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>";
    

    你可以用你想要的任何东西替换边界,但是它们必须是唯一的。

    为了使用PHP发送更强大和更灵活的电子邮件,我建议使用 SwiftMailer

    编辑:由于Outlook 2007有一个非常愚蠢的HTML呈现程序,您也可以尝试修复标记,有一个 </font> 从来没有在你的例子中打开过,不知道是真的邮件还是有问题的打字错误。

        2
  •  3
  •   Jim    14 年前

    我遇到了一个非常类似的问题,请尝试从退货中删除/R并仅使用/N。Outlook和D hotmail在使用/R/N时遇到问题。

        3
  •  2
  •   Michael Konečný    14 年前

    我确认交流的经验 詹莫森 已经共享。 必须将头中的CRLF更改为仅LF,然后它开始工作。

    (再次感谢微软,让我加班40%。

    同时也非常感谢Janmoesen的指点!搜索结束。)

        4
  •  2
  •   Morgan    12 年前

    我在Outlook 2007中遇到了同样的问题。

    答案很简单:替换 \ r\n 通过 \n

        5
  •  1
  •   John Conde    15 年前

    如果邮件是HTML格式的,则需要将其标识为:

    $header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
    
        6
  •  1
  •   dpb    15 年前

    我一直对mime编码的html邮件比较幸运。即使只有一个部分,我通常使用multipart/mixed并显式设置内容类型(text/html)。我不太熟悉PHP,但是 PEAR::Mail_Mime 包看起来像一个候选人。

    Outlook处理它应该不会有问题。(帝国主义 不应该 )

        7
  •  1
  •   janmoesen    15 年前

    我在Exchange(不仅仅是Outlook)和CRLF中遇到了类似结果的问题。基本上,我们发送邮件(在Debian上使用php和postfix)时,邮件头是用crlf分隔的,到达后,邮件头会损坏。当我换的时候 \r\n 简单地 \n 问题解决了。(该死的RFC!,嗯?)

    很明显,YMMV,因为不清楚您的其他邮件客户端是连接到与Outlook相同的服务器,还是使用单独的服务器。