简体   繁体   English

发送 HTML email 和 PHP

[英]Sending HTML email with PHP

I am trying to send an html email with PHP and it keeps coming just as text.我正在尝试发送 html email 和 PHP,它一直以文本形式出现。 All of the values are generated correctly from the php it is just text in the email. Here is the code:所有值都是从 php 正确生成的,它只是 email 中的文本。代码如下:

    $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:您在三行中的最后一行覆盖 header:

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

Should be (note the dot):应该是(注意点):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM