SMTP: Failed to connect socket: Unable to find the

2019-07-17 19:47发布

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?

标签: php ssl pear
3条回答
▲ chillily
2楼-- · 2019-07-17 20:02

Uncoment php_openssl.dll in php.ini

查看更多
爷的心禁止访问
3楼-- · 2019-07-17 20:15

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.

查看更多
神经病院院长
4楼-- · 2019-07-17 20:19

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.

查看更多
登录 后发表回答