dongzan0108 2015-03-27 10:39 采纳率: 0%
浏览 14
已采纳

使用电子邮件正文发送html

I am trying to insert and send email with html body but the received email is pure html text.I've added correct headers but seems that they not helping me ( or at least I think are correct one ).

Here is the code

if(isset($_POST['email'])) {
$email_to = "";
$email_subject = "";

$firstname = $_POST['name']; // required
$email = $_POST['email']; // required
$message = $_POST['message']; // not required
$phone = $_POST['phone'];
$captcha = $_POST['captcha'];
$subject = $_POST['subject']; // required  
    $email_message = "New email:

";
        $email_message .= '
       <html>
       <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <title>Untitled Document</title>
       </head>
       <body>            
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                <td align="center" valign="top" bgcolor="#838383" style="background-color:#838383;"><br>
                   <table width="600" border="0" cellspacing="0" cellpadding="0">
                       <tr>
                         <td align="left" valign="top"><img src="images/top.png" width="600" height="177" style="display:block;"></td>
                       </tr>
              <tr>
                         <td align="center" valign="top" bgcolor="#d3be6c" style="background-color:#d3be6c; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000000; padding:0px 15px 10px 15px;">
                      <div style="font-size:24px; color:#555100;"><br>
                     '.$firstname.'
                      </div><br>
                      <div>'.$subject.'</div>

            <div>
            '.$message.'
            '.$email.'
                    '.$phone.'
     </div></td>
 </tr>
 <tr>
   <td align="left" valign="top"><img src="images/bot.png" width="600" height="18" style="display:block;"></td>
 </tr>
 </table>
 <br>
 <br></td>
 </tr>
</table>
</body>
</html>';

        // create email headers
    $headers  = 'MIME-Version: 1.0' . "
";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
        $headers = 'From: '.$email."
".
        'Reply-To: '.$email."
" .
        'X-Mailer: PHP/' . phpversion();
        @mail($email_to, $email_subject, $email_message, $headers);
  }

http://pastebin.com/5aQh0Gvz

  • 写回答

1条回答 默认 最新

  • doubi1818 2015-03-27 10:45
    关注

    You were resetting $headers when setting the From: header:

    $headers  = 'MIME-Version: 1.0' . "
    ";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
    ";
    $headers .= 'From: '.$email."
    ". // << note the dot before = that wasn't here before making `$headers` to be resetted
    'Reply-To: '.$email."
    " .
    'X-Mailer: PHP/' . phpversion();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法