我有一个非常奇怪的问题,我似乎无法找出原因。我知道为什么它显然是由...引起的......当电子邮件的HTML内容包含内联CSS样式时。当我删除内联样式时,电子邮件就可以了。当我添加它时,它没有。
我正在运行这样的脚本:
$text_message = 'HELLO! Some more email content goes here';
$html_message = '<table>
<tbody><tr>
<td class="mcnTextContent" style="padding-top: 9px;padding-right: 18px;padding-bottom: 9px;padding-left: 18px;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;color: #606060;font-family: Helvetica;font-size: 15px;line-height: 150%;text-align: left;" valign="top">
<h3 style="margin: 0;padding: 0;display: block;font-family: Helvetica;font-size: 18px;font-style: normal;font-weight: bold;line-height: 125%;letter-spacing: -.5px;text-align: left;color: #606060 !important;">HELLO!</h3>Some more email content goes here
</td>
</tr>
</tbody></table>';
$link = 'link';
$text_message = sprintf($text_message, $msg_details['name'], $link, $this->setts['sitename']);
$html_message = sprintf($html_message, $msg_details['name'], $link, $this->setts['sitename']);
send_mail($msg_details['email'], 'Message Received - ' . $setts['sitename'], $text_message,
$this->setts['admin_email'], $html_message, null, $send);
然后是&#34; send_mail&#34;的后端。功能是:
function send_mail($to, $subject, $text_message, $from_email, $html_message = null, $from_name = null, $send = true, $reply_to = null)
{
global $setts, $current_version;
if ($send)
{
## set date
$tz = date('Z');
$tzs = ($tz < 0) ? '-' : '+';
$tz = abs($tz);
$tz = ($tz / 3600) * 100 + ($tz % 3600) / 60;
$mail_date = sprintf('%s %s%04d', date('D, j M Y H:i:s'), $tzs, $tz);
$uniq_id = md5(uniqid(time()));
## create the message body
$html_message = ($html_message) ? $html_message : $text_message;
$html_msg = "<!--\n" . $text_message . "\n-->\n". "<html><body>". $html_message . "</body></html>";
$from_name = (!empty($from_name)) ? $from_name : GMSG_MAIL_FROM_ADMIN;
switch ($setts['mailer'])
{
case 'sendmail': ## send through the UNIX Sendmail function
## create header
$header = "Date: " . $mail_date . "\n".
"Return-Path: " . $from_email . "\n".
"To: " . $to . "\n".
"From: " . $from_name . " <" . $from_email . ">\n".
(($setts['enable_bcc']) ? "Bcc: " . $setts['admin_email'] . "\n" : "").
"Reply-to: " . ((!empty($reply_to)) ? $reply_to : $from_email) . "\n".
"Subject: " . $subject . "\n".
sprintf("Message-ID: <%s@%s>%s", $uniq_id, $_SERVER['SERVER_NAME'], "\n").
"X-Priority: 3\n".
"X-Mailer: Sendmail [version " . $current_version . "]\n".
"MIME-Version: 1.0\n".
"Content-Transfer-Encoding: 7bit\n".
sprintf("Content-Type: %s; charset=\"%s\"","text/html",LANG_CODEPAGE).
"\n\n";
if ($from_email)
{
$output = sprintf("%s -oi -f %s -t", $setts['sendmail_path'], $from_email);
}
else
{
$output = sprintf("%s -oi -t", $setts['sendmail_path']);
}
if(!@$mail = popen($output, "w"))
{
echo GMSG_COULDNT_EXECUTE . ': ' . $setts['sendmail_path'];
}
fputs($mail, $header);
fputs($mail, $html_msg);
$result = pclose($mail) >> 8 & 0xFF;
if($result != 0)
{
echo GMSG_COULDNT_EXECUTE . ': ' . $setts['sendmail_path'];
}
break;
}
}
}
我知道,代码很乱......但它不是我自己的,它是我编辑的脚本。问题只是......每当我删除&#34;样式......&#34;在$ html_message变量中,HTML电子邮件正确显示,包括h3样式等。当我添加样式时,它只显示$ text_message内容。
哪些部分可以剥离或禁用HTML代码?
答案 0 :(得分:0)
可能是您的邮件客户端或邮件过滤器。
你好像很了解sendmail,用
做一些测试sendmail -oi -t < /tmp/email.txt