如何在不使用第 3 方 class 的情况下使用 PHP 发送 SMTP 电子邮件

How to send SMTP emails with PHP without using a 3rd party class

我一直在使用 PHPMailer 发送 SMTP 电子邮件,也听过一些人推荐各种其他第 3 方 classes。

我一直对 PHP 中没有此功能感到惊讶和失望。

我还需要使用第 3 方 class 才能这样做吗?如果没有,怎么办?如果是这样,知道为什么它不是本地的吗?

PHP确实有一个原生函数mail()可以发送邮件,但是效率不是很高。 来自官方 PHP 文档 -

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.

官方 PHP 文档建议使用 PEAR::Mail 库以获得高效的电子邮件支持。我宁愿使用 PHPmailer 或 Swift mailer(http://swiftmailer.org/),因为它们都有出色的支持并且有据可查。

如果您正在使用 windows,除非您的 PC 上安装了 smtp 服务器,否则 php mail() 函数将不起作用。 Windows 将电子邮件传递给电子邮件服务器,如果它可以通过您的防火墙进行访问,则该服务器会发送电子邮件。另请注意,记录的 mail() 不是发送电子邮件的正确方法。为了发送电子邮件,电子邮件必须以类似于 RFC 文档的方式编写。