【问题标题】:How to attach css while Sending html emails with PHP如何在使用 PHP 发送 html 电子邮件时附加 css
【发布时间】:2016-04-03 19:22:03
【问题描述】:

我必须在注册时发送电子邮件。这就是我现在正在做的,

$bodymessaage= '<table border="0" cellpadding="0" cellspacing="0" width="100%" >';
$bodymessaage.='</table>'  

我的图片在服务器上,我已经将它们的路径设置为绝对路径,我已经设置了这些标题

<?php $headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";?>

邮件功能是这样的。

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

现在正在发送邮件,其中包含所有内联图像和 stle,我的问题是如何在样式标签中附加我的 html 电子邮件头部部分中的 css 文件,请帮我解决这个问题,

【问题讨论】:

    标签: php html css email


    【解决方案1】:

    使用 html style 标签。我不是 100% 确定,但我相信它应该出现在 html body 之前。

    $bodymessage = '
    <style>
       table{
       background-color: blue;
       }
    </style>
    ';
    $bodymessaage .= '<table border="0" cellpadding="0" cellspacing="0" width="100%" >';
    $bodymessaage .='</table>';
    

    当然,这只是一个例子。

    正如 Fred 所提到的,&lt;style&gt; 标记被大多数电子邮件客户端忽略。所以不要使用它,而是使用内联 CSS:

    $bodymessaage .= '<table style="background-color: blue;" border="0" cellpadding="0" cellspacing="0" width="100%" >';
    $bodymessaage .='</table>';
    

    【讨论】:

    • 样式标签被大多数电子邮件客户端忽略,尤其是 Google、Hotmail、Yahoo。最好使用内联 CSS。
    • 内联 CSS 在 HTML 元素中应该是 style=" ",对吧?
    • 就是这样。第一个在大多数情况下会失败,而第二个会起作用。
    • 谢谢,我不知道。
    • 哦,你在这里忘记了一个结束分号$bodymessaage .='&lt;/table&gt;' ;-)
    猜你喜欢
    • 2014-09-23
    • 2015-11-28
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    相关资源
    最近更新 更多