在Symfony2中为电子邮件模板动态生成内联css样式

时间:2022-10-16 15:03:41

Is there a tool or a bundle in Symfony2 that allows me to create normal templates with css files, and then on the fly convert it to inline css rules so it can be used as the body of an email?

Symfony2中是否有工具或捆绑包允许我使用css文件创建普通模板,然后将其转换为内联css规则,以便它可以用作电子邮件的正文?

3 个解决方案

#1


4  

I know of three tools that can do this and which you can use in Symfony:

我知道有三种工具可以做到这一点,你可以在Symfony中使用它们:

  • Premailer is an online tool which provides this service. It has an API and a php wrapper for that API
  • Premailer是一个提供此服务的在线工具。它有一个API和该API的php包装器
  • CssToInlineClass is a php class that offers this functionality
  • CssToInlineClass是一个提供此功能的php类
  • Mailchimp offers a function in their api that offers this functionality
  • Mailchimp在他们的api中提供了一个提供此功能的功能

The first two don´t have a direct symfony implementation, though they will be easy to use. For mailchimp, there is a mailchimp bundle which offers this functionality, though the bundle is not very well documented.

前两个没有直接的symfony实现,虽然它们很容易使用。对于mailchimp,有一个mailchimp包提供了这个功能,虽然捆绑包没有很好的文档记录。

#2


4  

Today I discovered through another question that exists such a Symfony2 bundle that fits your needs (I didn't tested it).

今天我通过另一个问题发现存在这样一个符合您需求的Symfony2软件包(我没有测试过它)。

You can use ToInlineStyleEmailBundle, it embeds the CSSToInline library that Carlos Granados suggested in his answer.

您可以使用ToInlineStyleEmailBundle,它嵌入了Carlos Granados在其答案中建议的CSSToInline库。

With this Symfony2 bundle you can get the converter as a service ($this->get('css_to_inline_email_converter')) and then use it for your needs. It also supports templates generations.

使用此Symfony2软件包,您可以将转换器作为服务($ this-> get('css_to_inline_email_converter')),然后根据您的需要使用它。它还支持模板生成。

#3


1  

I've had great results with integrating the Emogrifier PHP class within CakePHP. Inlines all styles very nicely. Not sure if it has a Symfony bundle but shouldn't be hard to integrate.

我在CakePHP中集成了Emogrifier PHP类,取得了很好的效果。非常好地内联所有样式。不确定它是否有Symfony包但不应该难以集成。

https://github.com/jjriv/emogrifier

https://github.com/jjriv/emogrifier

#1


4  

I know of three tools that can do this and which you can use in Symfony:

我知道有三种工具可以做到这一点,你可以在Symfony中使用它们:

  • Premailer is an online tool which provides this service. It has an API and a php wrapper for that API
  • Premailer是一个提供此服务的在线工具。它有一个API和该API的php包装器
  • CssToInlineClass is a php class that offers this functionality
  • CssToInlineClass是一个提供此功能的php类
  • Mailchimp offers a function in their api that offers this functionality
  • Mailchimp在他们的api中提供了一个提供此功能的功能

The first two don´t have a direct symfony implementation, though they will be easy to use. For mailchimp, there is a mailchimp bundle which offers this functionality, though the bundle is not very well documented.

前两个没有直接的symfony实现,虽然它们很容易使用。对于mailchimp,有一个mailchimp包提供了这个功能,虽然捆绑包没有很好的文档记录。

#2


4  

Today I discovered through another question that exists such a Symfony2 bundle that fits your needs (I didn't tested it).

今天我通过另一个问题发现存在这样一个符合您需求的Symfony2软件包(我没有测试过它)。

You can use ToInlineStyleEmailBundle, it embeds the CSSToInline library that Carlos Granados suggested in his answer.

您可以使用ToInlineStyleEmailBundle,它嵌入了Carlos Granados在其答案中建议的CSSToInline库。

With this Symfony2 bundle you can get the converter as a service ($this->get('css_to_inline_email_converter')) and then use it for your needs. It also supports templates generations.

使用此Symfony2软件包,您可以将转换器作为服务($ this-> get('css_to_inline_email_converter')),然后根据您的需要使用它。它还支持模板生成。

#3


1  

I've had great results with integrating the Emogrifier PHP class within CakePHP. Inlines all styles very nicely. Not sure if it has a Symfony bundle but shouldn't be hard to integrate.

我在CakePHP中集成了Emogrifier PHP类,取得了很好的效果。非常好地内联所有样式。不确定它是否有Symfony包但不应该难以集成。

https://github.com/jjriv/emogrifier

https://github.com/jjriv/emogrifier