簡體   English   中英

無法執行:/ usr / sbin / sendmail -t -i

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

我嘗試通過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!";
}

我收到這個錯誤:

無法執行:/ usr / sbin / sendmail -t -i

我知道為什么我會收到此錯誤以及為什么電子郵件不發送?

我也聯系了公司,他們告訴我sendmail是活躍的,他們甚至為我重啟apache但我仍然得到同樣的錯誤。 他們告訴我,我應該設置一個主機mail.mydomain.ro才能工作,但在phpmailer示例中我沒有任何主機設置。

更新:如果我嘗試使用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

你為什么一直使用isSendmail() 如果你有一個奇怪的,自定義的sendmail仿真需要對它進行更多的控制而不是mail()提供的話,你應該只需要它; 這主要是出於歷史原因從后來更常見(PHPMailer自2001年以來一直存在!)。

如果你什么都不做,PHPMailer默認使用PHP的內置mail()函數。 但是,我建議你避免這種情況並使用isSMTP() - 它更可靠,更快速,更安全,並提供更好的發送反饋。 如果mail()有效,那么它應該涉及的是:

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

留下其他一切默認值應該沒問題。 這比定制sendmail配置要麻煩得多。

此外,你不是通過不設置Body幫助自己 - 這可能是你的錯誤的原因。 如果要發送純文本消息,請執行以下操作:

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

您可以通過以下方式解決問題:

  • 使用SMTP服務器(刪除isSendmail();並替換為$ mail-> IsSMTP();)
  • 嘗試更新sendmail
  • 檢查Web用戶是否可以訪問sendmail
  • 使用郵件功能發送電子郵件
  • 嘗試重新啟動Apache或您的Web服務器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM