简体   繁体   English

使用PHP发送HTML电子邮件

[英]Sending HTML Email Using PHP

I am trying to send html email using php. 我正在尝试使用php发送html电子邮件。 it is working fine on gmail, yahoo etc. but on my cpanel (Horde Email Client) the text is comming as an attachment and it is not showing any body. 它在gmail,yahoo等上正常工作,但是在我的cpanel(部落电子邮件客户端)上,该文本作为附件出现,并且没有显示任何正文。

These are the headers i am using 这些是我正在使用的标题

   $headers = "From: " ."XYZ<noRelpy@xxx.com>" . "\r\n";
   $headers .= "Reply-To: ". "noRelpy@xxx.com" . "\r\n";
   $headers .= "MIME-Version: 1.0" . "\r\n";
   $headers .= "Content-type:text/html;charset=us-ascii" . "\r\n";

I have also tried changing the charset to iso-8859-1 but still no sucess 我也尝试过将charset更改为iso-8859-1但仍然没有成功

Sending emails is hard, and fraught with serious security problems (mostly related to spam). 发送电子邮件非常困难,并且充满严重的安全问题(主要与垃圾邮件有关)。 It takes years to write code that sends email reliably. 编写可靠地发送电子邮件的代码需要花费数年的时间。

Instead of trying to do it yourself, this is a place where a third party library makes sense. 在这里,您可以尝试使用第三方库,而不是自己尝试这样做。

We have been using PHPMailer for years: http://code.google.com/a/apache-extras.org/p/phpmailer/ 我们已经使用PHPMailer多年了: http : //code.google.com/a/apache-extras.org/p/phpmailer/

It is difficult to write custom code that sends HTML e-mail, especially ones with embedded images or attachments. 编写发送HTML电子邮件的自定义代码非常困难,尤其是带有嵌入式图像或附件的自定义代码。 I have written a class to do this, but once you do, you realise there are a bunch of other features you need. 我已经编写了一个类来执行此操作,但是一旦完成,您就会意识到还需要其他许多功能。

Using a third-party library really is a better choice here if your core product is not a mailing library. 如果您的核心产品不是邮件库,那么使用第三方库确实是一个更好的选择。 PHPMailer is good, another good option is PHPMailer是好的,另一个好的选择是

swiftmailer swiftmailer

Good luck! 祝好运!

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

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