邮件发送错误:无法执行: /usr/sbin/sendmail
我使用debian服务器,文件权限是777(全部分配),所以我不能执行它,为什么?
//Create a new PHPMailer instance
$mail = new PHPMailer();
// Set PHPMailer to use the sendmail transport
$mail->isSendmail();
//Set who the message is to be sent from
$mail->setFrom('admin@test.com', 'test');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress($_POST['email'], $_POST['name']);
//Set the subject line
$mail->Subject = 'PHPMailer sendmail test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("from test");
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.gif');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}发布于 2014-01-13 18:44:49
在Ubuntu中,默认情况下不安装sendmail。您必须手动安装它:
sudo apt-get install sendmail-bin编辑1:
如果您使用的是PHPMailer,您可以使用以下方法设置Sendmail路径:
$mail->Sendmail = '/usr/sbin/sendmail';很容易测试PHP代码或邮件服务器配置中的问题,甚至可能是防火墙。试着从命令行运行,看看是否收到了电子邮件:
/usr/sbin/sendmail -v my@address.com < email.test此外,您实际上可以接收邮件,但它可以放在垃圾邮件文件夹中,因此也可以检查邮件。
编辑2:
还有一件事是,您应该安装sendmailconfig,然后运行它来配置它:
sudo sendmailconfig了解有关在Ubuntu上配置sendmail:sendmail: how to configure sendmail on ubuntu?的更多信息
发布于 2014-01-15 09:48:52
当前的问题似乎是您没有在系统上安装/usr/sbin/sendmail。提供此功能的MTA有多个,因此不需要安装Sendmail套件;实际上,我建议您不要安装Sendmail套件,而应该支持Postfix或一些真正简单的MTA,比如smtpd。Provides: sendmail应该做的任何包。
需要指出的另一个问题是chmod 777权限。你绝对不应该在生产系统上制造任何东西--可写的。PHP脚本的正确权限是755,如果您可以信任该组,则可能是775。httpd进程当然不需要能够写入脚本--实际上,绝对不应该允许向脚本文件写入任何东西。
https://stackoverflow.com/questions/21098855
复制相似问题