I try to send an email via phpmailer and this is my code:
$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
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. 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.
UPDATE: In case I try to use SMTP I get this error:
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? You should only need it if you have a weird, customised sendmail emulation that requires more control over it than mail()
provides; it's mainly there for historical reasons from back when that was more common (PHPMailer has been around since 2001!).
If you simply do nothing, PHPMailer defaults to using PHP's built-in mail()
function. However, I'd recommend you avoid that and use isSMTP()
anyway - it's more reliable, faster, more secure, and provides better feedback on sending. If mail()
works, all it should involve is adding:
$mail->isSMTP();
$mail->Host = 'localhost';
Leaving everything else with defaults should be fine. This is significantly less hassle than customising a sendmail config.
Also, you're not helping yourself by not setting Body
- that may be the cause of your error. If you want to send a plain-text-only message, do this:
$mail->isHTML(false);
$mail->Body = 'Hello';
You can resolve your probleme by :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.