使用PHP邮件功能生成的邮件仅显示代码

时间:2014-09-15 06:53:23

标签: php html email magento

我编写了一个使用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的位置。

3 个答案:

答案 0 :(得分:1)

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

参考网址 - PHP mailer example url

答案 1 :(得分:0)

使用以下标题行

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

答案 2 :(得分:0)

从$ 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";