简体   繁体   English

用PHP发送邮件

[英]Send Mail with PHP

We are sending HTML mails to our clients but some clients getting HTML code instead of proper formatted output. 我们向客户发送HTML邮件,但有些客户端获取HTML代码而不是正确的格式化输出。 We can't ask our client to changes settings etc.So, how can i send mail to deliver proper formatted output. 我们不能要求我们的客户更改设置等。因此,我如何发送邮件以提供正确的格式化输出。

Sending the header Content-Type: text/html is sufficient for any client that can display HTML to treat your message as such. 发送标题Content-Type: text/html足以让任何可以显示HTML的客户端对您的消息进行处理。 The problem is, not all clients understand HTML... 问题是,并非所有客户都理解HTML ...

The safest bet is to always send a multipart message. 最安全的选择是始终发送多部分消息。 It contains HTML for those clients that understand it and normal text for those that do not. 它包含了解其理解的客户端的HTML和不理解它的普通文本。

This tutorial covers the basic syntax. 本教程介绍了基本语法。

You need to send the emails in multipart format. 您需要以多部分格式发送电子邮件。 This will enable the mail client to display a text version of your email if they do not support HTML. 这将使邮件客户端能够显示电子邮件的文本版本(如果它们不支持HTML)。 This will also require that you have both a text/html version of the email, or use a descent html2text converter. 这还要求您同时拥有电子邮件的text / html版本,或使用descent html2text转换器。

I would recommend using the PHPMailer class to drastically simplify the process of sending the HTML emails with text content. 我建议使用PHPMailer类来大大简化发送带有文本内容的HTML电子邮件的过程。

See, http://sourceforge.net/projects/phpmailer/ 见, http://sourceforge.net/projects/phpmailer/

I would highly recommend the http://swiftmailer.org/ library. 我强烈推荐http://swiftmailer.org/库。

See http://masom.posterous.com/using-swiftmailer-in-lithium for an example on php 5.3+ 有关php 5.3+的示例,请参阅http://masom.posterous.com/using-swiftmailer-in-lithium

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM