使用PHP发送HTML电子邮件 [英] Sending HTML email with PHP

查看:38
本文介绍了使用PHP发送HTML电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP发送html电子邮件,并且它一直以文本形式发送.所有值都是从php正确生成的,它只是电子邮件中的文本.这是代码:

I am trying to send an html email with PHP and it keeps coming just as text. All of the values are generated correctly from the php it is just text in the email. Here is the code:

    $to='xxxxxxx@xxxxxxx.com';
    $from = 'xxxxxxx@xxxxxxxx.com';
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers = "From: $from \r\n";
    $subject = "Print Run: " . $run . " is ordered";
    $body ="<html>
            <head>
            </head>
            <body>
            <table>
                <tr>
                    <th>Company</th>
                    <th>Quantity</th>
                    <th>Size</th>
                    <th>Date Added</th>
                    <th>
                    </th>
                </tr>";
            for($i = 0; $i < $arraySize; $i++){     
                $body .= "<tr><td>" . $companyName[$i] . "</td><td>" . $quantity[$i] . "</td><td>" . $cardSize[$i] . "</td><td>" . $dateAdded[$i] . "</td></tr>";
            }
            $body .= "<tr>
                        <td style=\"font-weight:bold; border-style:solid; border-top-width:1px;\">Totals</td>
                        <td style=\"font-weight:bold; border-style:solid; border-top-width:1px;\">" . $totals . "</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        </tr>
                        </table>
                        </body>
                        </html>";

    mail($to,"Print Run: " . $run . " is ordered",$body,$headers);

推荐答案

您会在三行的最后一行覆盖标头:

You overwrite the header on the last of the three lines:

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

应该是(请注意点):

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

这篇关于使用PHP发送HTML电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆