繁体   English   中英

PHP中的电子邮件正文中的问题

[英]issue in body of the e-mail in php

我通过php发送邮件,在消息部分,我的代码如下:

$email_body = "<style type=\"text/css\">
 p {padding:0 !important; margin:0 !important;}
 td {padding:0 10px !important; margin:0 !important; font-family:Verdana, Geneva, sans-serif;}
 td table td {padding:0 !important;}
 </style>
<table align=\"center\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" style=\"border-collapse:collapse; border:1px solid #565656; font-family:Verdana, Geneva, sans-serif; width:800px;  margin-top:0px; color:#565656;font-weight:normal;font-size:12px; text-align:justify; line-height:1.5em\">
  <tbody>
   <tr>
     <td style=\"border-collapse:collapse; padding-top:10px !important;\">
      message
     </td>
   </tr>
  </tbody>
 </table>";

但是在我的邮件中,无论是为$ email_body而不是表格格式编写的,我都获得完整的html代码。 怎么做? 谢谢。

您需要设置正确的标题:

$to       = 'foo@bar.baz';
$subject  = 'foobar';
$message  = '...'; // the html
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);

看看手册: http : //php.net/manual/en/function.mail.php


您还需要一个完整的html文档,即:

html
  head
    title
    style
  body
    table

提示,如果您发送html邮件,请不要使用样式标签。 我经常使用此预邮寄器: http ://premailer.dialect.ca/

暂无
暂无

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

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