简体   繁体   English

无法执行:/ usr / sbin / sendmail -t -i

[英]Could not execute: /usr/sbin/sendmail -t -i

I try to send an email via phpmailer and this is my code: 我尝试通过phpmailer发送电子邮件,这是我的代码:

$mail = new PHPMailer;       
$mail->isSendmail();

$mail->setFrom('from@example.com', 'First Last');        
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'PHPMailer sendmail test';
$mail->AltBody= 'This is a plain-text message body';

if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

And I get this error: 我收到这个错误:

Could not execute: /usr/sbin/sendmail -t -i 无法执行:/ usr / sbin / sendmail -t -i

Any ideea why I get this error and why the email is not sending ? 我知道为什么我会收到此错误以及为什么电子邮件不发送?

I also contacted the company and they told me that sendmail is active and they even did a apache restart for me but I still get the same error. 我也联系了公司,他们告诉我sendmail是活跃的,他们甚至为我重启apache但我仍然得到同样的错误。 They told me that I should set a host mail.mydomain.ro in order to work, but in the phpmailer example I don't have any host to set. 他们告诉我,我应该设置一个主机mail.mydomain.ro才能工作,但在phpmailer示例中我没有任何主机设置。

UPDATE: In case I try to use SMTP I get this error: 更新:如果我尝试使用SMTP,我会收到此错误:

2017-01-25 19:56:44 SERVER -> CLIENT: 220-prime.mycompany.ro ESMTP Exim 4.87 #1 Wed, 25 Jan 2017 21:56:44 +0200 
220-We do not authorize the use of this system to transport unsolicited,220 and/or bulk e-mail.
2017-01-25 19:56:44 CLIENT -> SERVER: EHLO www.mywebsite.ro
2017-01-25 19:56:44 SERVER -> CLIENT: 250-prime.mycompany.ro Hello www.mywebsite.ro [some ip]
                                  250-SIZE 52428800
                                  250-8BITMIME
                                  250-PIPELINING
                                  250-AUTH PLAIN LOGIN
                                  250-STARTTLS
                                  250 HELP
2017-01-25 19:56:44 CLIENT -> SERVER: STARTTLS
2017-01-25 19:56:44 SERVER -> CLIENT: 220 TLS go ahead
2017-01-25 19:56:44 SMTP Error: Could not connect to SMTP host.
2017-01-25 19:56:44 CLIENT -> SERVER: QUIT
2017-01-25 19:56:44 SERVER -> CLIENT: 221 prime.mycompany.ro closing connection
2017-01-25 19:56:44 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Why are you using isSendmail() at all? 你为什么一直使用isSendmail() You should only need it if you have a weird, customised sendmail emulation that requires more control over it than mail() provides; 如果你有一个奇怪的,自定义的sendmail仿真需要对它进行更多的控制而不是mail()提供的话,你应该只需要它; it's mainly there for historical reasons from back when that was more common (PHPMailer has been around since 2001!). 这主要是出于历史原因从后来更常见(PHPMailer自2001年以来一直存在!)。

If you simply do nothing, PHPMailer defaults to using PHP's built-in mail() function. 如果你什么都不做,PHPMailer默认使用PHP的内置mail()函数。 However, I'd recommend you avoid that and use isSMTP() anyway - it's more reliable, faster, more secure, and provides better feedback on sending. 但是,我建议你避免这种情况并使用isSMTP() - 它更可靠,更快速,更安全,并提供更好的发送反馈。 If mail() works, all it should involve is adding: 如果mail()有效,那么它应该涉及的是:

$mail->isSMTP();
$mail->Host = 'localhost';

Leaving everything else with defaults should be fine. 留下其他一切默认值应该没问题。 This is significantly less hassle than customising a sendmail config. 这比定制sendmail配置要麻烦得多。

Also, you're not helping yourself by not setting Body - that may be the cause of your error. 此外,你不是通过不设置Body帮助自己 - 这可能是你的错误的原因。 If you want to send a plain-text-only message, do this: 如果要发送纯文本消息,请执行以下操作:

$mail->isHTML(false);
$mail->Body = 'Hello';

You can resolve your probleme by : 您可以通过以下方式解决问题:

  • Using SMTP server ( delete isSendmail(); and replace by $mail->IsSMTP(); ) 使用SMTP服务器(删除isSendmail();并替换为$ mail-> IsSMTP();)
  • Try to update sendmail 尝试更新sendmail
  • Check if Web user can access to sendmail 检查Web用户是否可以访问sendmail
  • Use mail function to send email 使用邮件功能发送电子邮件
  • Try to restart Apache or your web server 尝试重新启动Apache或您的Web服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM