簡體   English   中英

發送 HTML email 和 PHP

[英]Sending HTML email with PHP

我正在嘗試發送 html email 和 PHP,它一直以文本形式出現。 所有值都是從 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);

您在三行中的最后一行覆蓋 header:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM