PEAR Mail unable to connect to Gmail SMTP, failed to connect to socket
Your code is correct
I tried to test my gmail account. Mail sending was successful.
Check your socket connection
<?php
error_reporting(E_ALL);
var_dump(fsockopen("ssl://smtp.gmail.com", 465, $errno, $errstr));
var_dump($errno);
var_dump($errstr);
resource(4) of type (stream)
int(0)
string(0) ""
The "Use the Gmail SMTP Server" section of this guide says you need to enable "Less secure apps".
Your host
configuration shouldn't contain the protocol. The reason it's failing is because it's probably trying to perform a DNS Lookup on ssl://smtp.gmail.com
and failing.
Change
'host' => 'ssl://smtp.gmail.com',
to
'host' => 'smtp.gmail.com',