在不发送电子邮件的情况下测试phpmailer


Testing phpmailer without sending out emails

我的系统上已经有phpmailer了。我正在更新一些使用它发送电子邮件的代码,我只需要测试以确保更新发送了正确的信息,但不会在发送给数百人时发送实际的电子邮件。

有没有一种快速的方法可以将phpmailer重定向到一个文件,或者更好的方法是,如果phpmailer使用sendmail,则将该命令重定向到文件?这是一个测试服务器,因此最好将所有邮件功能重定向到一个文件或其他文件。

您可以将php.ini中的sendmail_path设置为您想要的任何值。例如,它可以是tee -a mail.log,以便将所有内容都记录到一个文件中。

您可以使用MailHog

https://github.com/mailhog/MailHog

只需在应用程序中设置MailHog,并在PHPMailer中设置配置即可主机=>"邮件"端口=>1025