SMTP: Failed to connect socket: Unable to find the socket transport “ssl”

独自空忆成欢 提交于 2019-12-24 03:12:11

问题


I've been trying to get to be able to send emails with Pear on WAMP through GMail, and after spending hours setting it all up and figuring out all the errors I was getting, I thought I was so close, until I started getting this error:

Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (code: -1, response: )]

Using this code:

<?php require_once "info.php"; require_once "Mail.php"; // info.php contains the variable $password
$from = "Me <myemail@gmail.com>";
$to = "Me <myemail@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "myemail@gmail.com";
$password = "$password";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
 'port' => $port,
 'auth' => true,
 'username' => $username,
 'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>

I've gone through and uncommented extension=php_openssl.dll in the (correct) php.ini, and made sure that the extension_dir was pointing to the DLLs. I've used phpinfo(); and I've seen multiple mentions of SSL:

I see mod_ssl in Loaded Modules.

Under the mysqlnd heading it has an entry SSL: supported.

And under the Phar heading there's the entry Native OpenSSL support: enabled.

I've also turned off my firewall, just to check, I've restarted my computer, and I've checked practically every question like mine on this site, and I still haven't found a solution.

I'm at a loss of what to do next. What do I need to enable/check to get it working?


回答1:


Open up the Port 465 open to smtp.gmail.com in your firewall :)

This will help

Then there may be problem with your host or else,

Try This - this is working for me

Did you allow SMTP in your Gmail

Check that 'Settings' is active for the SMTP server in your Gmail Settings.




回答2:


Uncoment php_openssl.dll in php.ini




回答3:


The answer was simple; The first thing you should do:

  1. Open the file php.ini then try to search the key extension. Then if you cannot find this extension=php_openssl.dll and please write it but make sure you remove ; before the word extension.

  2. Once you save it, please restart again your Xampp server. After that, everything is good.



来源:https://stackoverflow.com/questions/16642346/smtp-failed-to-connect-socket-unable-to-find-the-socket-transport-ssl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!