使用PHP邮件函数生成的邮件只显示代码


Mail generated using PHP mail function showing only code

我已经编写了一个代码来使用PHP mail()函数发送邮件

    $message = "
            <html>
            <head>
            <title>TITLE</title>
            </head>
            <body>
            <p>Customer ".$customerName." with id ".$customerId." wishes to place order for the following products that are currently note available in stock</p>
            <table>
            <tr>
            <th align='center'>Product Name</th>
            <th align='center'>Product Id</th>
            <th align='center'>Product Part Number</th>
            <th align='center'>Quantity</th>
            </tr>"
            .$content.
            "
            </table>
            </body>
            </html>
";

$headers = "MIME-Version: 1.0" . "'r'n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "'r'n";
    // More headers
     $headers .= 'From: '.$customerEmail.'' . "'r'n";

    mail($to,$subject,$message,$headers);

邮件对我来说很好,但对客户来说,它看起来像这个

From:
Sent: None
To: orders@xxxxx.com
Subject: SUBJECT
Content-type:text/html;charset=UTF-8
From: xxxx@xxxx.com
Message-Id: <20140908144611.165ACC36BC@SV08.xxxxxx.com>
Date: Mon,  8 Sep 2014 17:46:11 +0300 (AST)
X-Nonspam: None
X-Antivirus: avast! (VPS xxx-0, 09/09/2014), Inbound message
X-Antivirus-Status: Clean

            <html>
            <head>
            <title>TITLE</title>
            </head>
            <body>

    <p>Customer XXXX with id 3
wishes to place order for the following products that are currently not
available in stock</p>
                <table>
                <tr>
                <th align='center'>Product Name</th>
                <th align='center'>Product Id</th>
                <th align='center'>Product Part Number</th>
                <th align='center'>Quantity</th>

    </tr><tr><td
align='center'>SCREW;BHHS;3/8-16 X .75</td><td align='center'>3237<td
align='center'>35059</td><td align='center'>6</td></tr>
            </table>
            </body>
            </html>

我不明白为什么它对我们的测试有效,但对客户无效。我使用我的gmail帐户进行了测试,它显示出客户在公司域上使用邮件id的位置很好。

我建议您使用带有谷歌邮件smtp凭据的phpMailer库,而不是php邮件功能。这将帮助您发送HTML模板邮件。

参考URL-PHP邮件示例URL

使用以下标题行

$headers  = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";

从$message中删除和标记。并将标题更改为

$headers = "From: " . strip_tags($_POST['req-email']) . "'r'n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "'r'n";
$headers .= "CC: susan@example.com'r'n";
$headers .= "MIME-Version: 1.0'r'n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";