如何发送HTML / CSS电子邮件? [英] How to send HTML/CSS emails?

查看:162
本文介绍了如何发送HTML / CSS电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数电子邮件客户端在HTML电子邮件(包括Gmail和Hotmail)中都会读取CSS的问题。我经常使用这个服务将我的HTML / CSS转换成适当的电子邮件格式,以便用户的一切看起来都很正常。基本上它是将所有CSS转换为内联样式:

Most email clients have problems reading CSS in HTML emails (including Gmail and Hotmail). I often use this service to convert my HTML/CSS to proper email format so that everything looks normal on the user's end. Basically what it does is convert all CSS to inline styles:

http://premailer.dialect.ca/

您还有其他任何方法可以在HTML电子邮件中发送CSS吗?我自动生成电子邮件,并且由于一些限制,我无法修改内联样式。

Do any of you have any other methods for sending CSS in your HTML emails? I automatically generate the emails, and due to some restrictions, I can't modify the the inline styles.

推荐答案

至于直接格式,我一直做内联CSS样式,但是我使用SwiftMailer( http://swiftmailer.org/ )for PHP5处理电子邮件功能,它已经非常有帮助。

As for direct format, I've always done inline CSS styling, however I use SwiftMailer (http://swiftmailer.org/) for PHP5 to handle email functionality and it has helped immensely.

您可以发送具有不同格式的多部分消息,因此如果电子邮件客户端不喜欢HTML版本,则可以默认使用文本版本,以便至少知道一些内容正在通风干净。

You can send multipart messages with different formats so if the email client doesn't like the HTML version, you can always default to the text version so you know at least something is getting through clean.

在您的views文件夹中,您可以为不同的电子邮件格式设置路由(我也使用smarty,因此.tpl扩展名)。这是一个典型的SwiftMailer :: sendTemplate()函数在您设置模板时的样子:

In your "views" folder, you can set apart routes for different email formats (I use smarty too, hence the .tpl extension). Here's what a typical SwiftMailer::sendTemplate() function would look like when you're setting up the templates:

 $email_templates = array('text/html' => 'email/html/' . $template . '.en.html.tpl',
                        'text/plain' => 'email/text/' . $template . '.en.txt.tpl');

foreach ($email_templates as $type => $file) {
  if ($email->template_exists($file)) {
    $message->attach(new Swift_Message_Part($email->fetch($file), $type));
  } elseif ($type == 'text/plain') {
    throw new Exception('Could not send email -- no text version was found');
  }
}

你会得到想法。 SwiftMailer拥有一大堆其他好的东西,包括返回无法投递地址,记录传送错误以及限制大型电子邮件批处理。我建议你检查一下。

You get the idea. SwiftMailer has a bunch of other good stuff, including returning "undeliverable" addresses, logging delivery errors, and throttling large email batches. I'd suggest you check it out.

这篇关于如何发送HTML / CSS电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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