php - 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 吗?
谢谢你。
解决方案
当您使用 PHP 的mail()
函数(PHPMailer 默认使用的)时,它会打开一个 shell 并调用属于您本地邮件服务器的 sendmail 二进制文件(用于从命令行提交电子邮件消息的客户端程序)。如果您没有本地邮件服务器,它将无法工作,并且您会收到您所看到的错误。如果有邮件服务器,您可能会收到相同的错误,但您没有运行 sendmail 的权限。
您需要执行以下操作之一:
- 安装邮件服务器(如 postfix)
- 通过 SMTP 与本地服务器通信(不会以同样的方式受到权限问题的影响
mail()
) - 使用 SMTP 通过远程邮件服务器发送,无论是您的 ISP 还是其他一些服务器,例如 gmail(如果您的 ISP 允许出站 SMTP)。
推荐阅读
- java - 在Java中将null替换为空字符串
- r - 如何修改排名标准以指定截止日期
- javascript - 使用 Open Street Maps 在给定地图上显示给定城市
- python - 线程和 mss 问题 - 第二次运行函数时出错
- android-studio - 使用带有 MediaPlayer 的波形文件资源
- python - 在 SWIG 中获取从 C++ 到 Python 的 char* 输出
- javascript - 使用 JavaScript.evaluate 在 WKWebView 中检测按钮单击(按类名)
- php - 从 fgetcsv 生成的打印数组抛出未定义的索引
- asp.net - 我们不能使用此代码在 ASP.NET MVC 中显示图像吗?
- c++ - 实际运行时和运行时复杂度之间的悖论