通过PHP发送HTML电子邮件,包括CSS样式表 [英] Send HTML email including CSS style sheet via PHP

查看:378
本文介绍了通过PHP发送HTML电子邮件,包括CSS样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将包含CSS样式表的HTML页面发送到电子邮件帐户。问题在于CSS样式表根本不可见。我是否必须内联每个CSS样式?这似乎是效率很低的方法。还有其他想法吗?

I want to send a HTML page that contains CSS stylesheet to an email account. The problem is that the CSS style sheet is not visible at all. Do I have to inline every CSS styling? It seems to be highly inefficient method. Any others ideas ?

以下是用于发送电子邮件的PHP代码:

Below is the PHP code for sending the email :

<?php
$to = "myaccount@gmail.com";

// subject
$subject = "Test mail";

// message
$message = file_get_contents("index.html");

// from
$from = "myaccount@gmail.com";

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= "From:" . $from;

// Mail it
mail($to,$subject,$message,$headers);

echo "Mail Sent.";
?>

非常感谢您的帮助。

推荐答案

Google,Outlook,Yahoo所有主要的电子邮件服务提供商都不允许CSS外部文件。他们选择内联样式和表格来呈现具有任何样式的正确电子邮件可能听起来过时了。

Google, Outlook, Yahoo all the major email service providers do not allow CSS external files. It may sound antiquated that they have opted for inline styles and tables to render a proper email message with any styling.

编写代码可能很繁琐,但是像 https:// litmus这样的公司。 com / 和envato将帮助解决某些模板和格式问题。

It may be tedious to code but companies like https://litmus.com/ and envato will help with some templates and formatting issues.

我的2美分:电子邮件提供商无法信任所发送信息的所有来源因此,这是阻止恶意代码的一种方法。

my 2¢'s: email providers can't trust all sources of information being sent and so this is a way of keeping the malicious code at bay.

这篇关于通过PHP发送HTML电子邮件,包括CSS样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆