[SOLVED] smtp gmail Swift_Connection_Exception

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
hectorsc
Forum Newbie
Posts: 2
Joined: Thu Apr 12, 2007 2:39 pm

[SOLVED] smtp gmail Swift_Connection_Exception

Post by hectorsc »

I pulled this code off another thread and put in my info

Code: Select all

<php
  require("swift/Swift.php");
  require("swift/Swift/Connection/SMTP.php");
        $smtp = new Swift_Connection_SMTP('smtp.gmail.com',
                                                     Swift_Connection_SMTP::PORT_SECURE,
                                                     Swift_Connection_SMTP::ENC_TLS);
        $smtp->setUsername("xxxxx@gmail.com");
        $smtp->setPassword("xxxxxx");
        $swift = new Swift($smtp);   

       $message = new Swift_Message("subject", "body");



                           //Start a new list

                    //$recipients = new Swift_RecipientList();


                 //$recipients->addTo("xxxxxxx@hotmail.com"); //or we can just add the address




           $result = $swift->send($message, $recipients, new Swift_Address("xxxxxxxx@hotmail.com", "Hector Scout"));

       if (!$result){

           echo "error: ";

             }
            $swift->disconnect(); 
?>

I'm getting this error:

Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'The SMTP connection failed to start [tls://smtp.gmail.com:465]: fsockopen returned Error Number 40 and Error String 'Unable to find the socket transport "tls" - did you forget to enable it when you configured PHP?'' in C:\Program Files\php\PEAR\swift\Swift\Connection\SMTP.php:291 Stack trace: #0 C:\Program Files\php\PEAR\swift\Swift.php(220): Swift_Connection_SMTP->start() #1 C:\Program Files\php\PEAR\swift\Swift.php(97): Swift->connect() #2 D:\www\sendEmail.php(37): Swift->__construct(Object(Swift_Connection_SMTP)) #3 {main} thrown in C:\Program Files\php\PEAR\swift\Swift\Connection\SMTP.php on line 291

Any help?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

PHP isn't compiled with OpenSSL. It needs to be or this wont work.

EDIT | I'm not sure how ssl works on windows. I think there will be an extension you need to enable.
hectorsc
Forum Newbie
Posts: 2
Joined: Thu Apr 12, 2007 2:39 pm

Solved

Post by hectorsc »

That did it. I just had to uncomment the "extension=php_openssl.dll" line in php.ini and it works now. Thank you much. Hooray!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Solved

Post by Chris Corbyn »

hectorsc wrote:That did it. I just had to uncomment the "extension=php_openssl.dll" line in php.ini and it works now. Thank you much. Hooray!
Is it that simple? I'm glad someone clarified this since this is pretty common with the windows users and I don't run PHP on windows so have never really been able to provide a definitive answer. I'll document that :)
Post Reply