I have a php scrip that emails. After the recent update to php and php-pear to 5.6 it no longer works and I get a authentication error.
$from = "no-reply@mydomain.net";
$port = "587";
$to=$d_uname;
$host = "smtp.sendgrid.net";
$username = "username";
$password = "password";
$headers = array ('From' => $d_replyto,
'To' => $to,
'Subject' => $d_subject,
'MIME-Version' => "1.0",
'Content-type' => "text/plain; charset=utf-8",
);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
#Email it
if (PEAR::isError($smtp)) {
error_log("<p>" . $smtp->getMessage() . "</p>");
}
$mail = $smtp->send($to, $headers, $d_message);
When trying to send emails this way I get the following error:
authentication failure [SMTP: STARTTLS failed (code: 220, response: Begin TLS negotiation now)]
Any ideas what's wrong here? Downgrading PHP and PHP-pear resolves the issue.
Cheers!
I had the same problem and was looking for an answer. This question is kinda old but I will leave a few words of explanation for someone else. The problem is that PEAR SMTP class, which extend PEAR Mail, is not yet updated for php 5.6. Since php 5.6 you won't be able to use PEAR Mail for "unclean" TLS connections. It has something to do with OpenSSL changes. It will work for some SMTP's, like Gmail's on port 465, but nowhere else. You need to use 'auth' => false or switch to PHP Mailer
You can hard-code the options required to allow self-signed certificates by including them on line 208 of Socket.php
else{ // if $fp does exist
stream_context_set_option($fp, 'ssl', 'verify_peer', false);
stream_context_set_option($fp, 'ssl', 'allow_self_signed', true);
stream_context_set_option($fp, 'ssl', 'verify_peer_name', false);
}
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.