2013-08-23 42 views
0

我设计了一个HTML页面,然后将其转换为在PHP中使用以发送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 = "[email protected]"; 
$subject = "Pulling my hair out"; 
$headers = "From: [email protected]"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

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

即使它看起来很完美的一个独立的HTML页面(我甚至提出,呼应了$消息阵列测试PHP页面,它仍然看起来完美)就会有奇怪的事情错了,在电子邮件(发送后)。

有时候会有随机的!在文本的中间。有时,标签中的样式不会显示在电子邮件中(当我检查电子邮件的HTML时)。它似乎不稳定。

我在这里错过了什么?

+0

如果您认为编写适用于主流浏览器的html很难,那么与为所有各种电子邮件客户端编写html相比,这没什么。我可以写卷,但我懒惰:http://www.sitepoint.com/code-html-email-newsletters/ – 2013-08-23 02:43:34

回答

0

您可以在一个页面emailresetTemplate.php 在这个页面中写这些线的

<?php ob_start();?>

这里做你的HTML的东西.......例子下面........ .. 像.......
<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 protected]' . "\r\n" . 
         'Reply-To: [email protected]' . "\r\n" . 
         'X-Mailer: PHP/' . phpversion(); 
         @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."); 
         }