0

我设计了一个 HTML 页面,然后将其转换为在 PHP 中使用,以便发送 HTML 电子邮件。

$message = '<!DOCTYPE html>';
$message .= '<html>';
$message .= '<body bgcolor="#E8E8E8 ">';
$message .= '<table bgcolor="white" >';
$message .= '<tr>';
$message .= '<td style="font-family:\'Helvetica Neue\',Helvetica,Arial,sans-serif;">';
$message .= '<img src="#" width="200px">';
$message .= 'This is a test page.';
$message .= '</td>';
$message .= '</tr>';
$message .= '</table>';
$message .= '</body>';
$message .= '</html>';

$to = "you@example.com";
$subject = "Pulling my hair out";
$headers = "From: me@example.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

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

尽管它作为一个独立的 html 页面看起来很完美(我什至制作了一个与 $message 数组相呼应的测试 php 页面,它看起来仍然很完美)它在电子邮件中会出现奇怪的问题(在它发送之后) .

有时会随机出现!在正文中间。有时标签中的样式不会显示在电子邮件中(当我“检查”电子邮件的 html 时)。看起来很不稳定。

我在这里想念什么?

4

1 回答 1

-1

您可以制作一页 emailresetTemplate.php 在此页面中写下这些行

<?php ob_start();?>
//do your html stuff here ....... Example Below..........
<div style="width:698px; margin:0 auto; position:relative;">
    <div>
        <div style="background:url(<?php echo ABSOLUTE_PATH; ?>images/email/restpass/header.png) no-repeat; width:680px; height:127px; margin:0 0 0 10px;"></div>
    </div>
    <?php    
        $contents = ob_get_contents();
        ob_clean();
        include("emailresetTemplate.php");
        $to = $email;
        $subject = 'Your Password Reset Request';
        $message = $contents;
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: email@example.com' . "\r\n" .
                'Reply-To: email@example.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
        if(@mail($to, $subject, $message, $headers)){
            print "An email containing the password has been sent to you at " . $row["eMail"];
        } else {
            echo("No such login in the system. please try again.");
        }
   ?>
</div>
于 2013-10-14T22:35:39.077 回答