ninpot18
ninpot18

Reputation: 127

Pear Mail (Gmail SMTP) - Failed to connect socket

I'm trying to send an email to gmail using Pear Mail but I'm having 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: )]

Here's my code:

<?php
    require_once 'Mail.php';

    $from = "[email protected]";
    $to = "[email protected]";
    $subject = "Subject";
    $body = "Hello!"; 

    $host = "ssl://smtp.gmail.com";
    $port = "465";
    $username = "[email protected]";
    $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 $mail->getMessage();
} else {
echo "Message sent successfully!";
}
?>

I've read almost everything regarding same issues with mine, I've tried phpmailer and I found it hard, I tried removing the comment on extension=php_openssl.dll found on php.ini, restarted apache, changed 465 to 587 or so and no luck! Windows firewall is not on. What am I doing wrong? Please help!

Thanks!

Upvotes: 1

Views: 3264

Answers (1)

ninpot18
ninpot18

Reputation: 127

This one's already working! Sorry I edited the wrong php.in file; it should be the one inside bin folder.

Upvotes: 1

Related Questions