首页 > 解决方案 > phpmailer和sendmail

问题描述

当我尝试发送电子邮件时出现此错误。我使用最新的phpmailer。

Could not execute: /usr/sbin/sendmail -t -i -f

" object(PHPMailer\PHPMailer\PHPMailer)#42 (75) { ["Priority"]=> NULL ["CharSet"]=> string(5) "utf-8" ["ContentType"]=> string(10) "text/plain" ["Encoding"]=> string(16) "quoted-printable" ["ErrorInfo"]=> string(73) "Could not execute: /usr/sbin/sendmail -t -i -f 

到目前为止,它工作正常,但无法发送带有此问题的电子邮件。

不确定,但我认为一些主机插入了限制,你有什么想法改变它吗?使用 SMTP 吗?

谢谢你。

标签: phpphpmailer

解决方案


当您使用 PHP 的mail()函数(PHPMailer 默认使用的)时,它会打开一个 shell 并调用属于您本地邮件服务器的 sendmail 二进制文件(用于从命令行提交电子邮件消息的客户端程序)。如果您没有本地邮件服务器,它将无法工作,并且您会收到您所看到的错误。如果有邮件服务器,您可能会收到相同的错误,但您没有运行 sendmail 的权限。

您需要执行以下操作之一:

  1. 安装邮件服务器(如 postfix)
  2. 通过 SMTP 与本地服务器通信(不会以同样的方式受到权限问题的影响mail()
  3. 使用 SMTP 通过远程邮件服务器发送,无论是您的 ISP 还是其他一些服务器,例如 gmail(如果您的 ISP 允许出站 SMTP)。

推荐阅读