Unable to send email in Zend using gmail SMTP. Getting Fatal error: Uncaught exception 'Zend_Mail_Protocol_Exception'. How to fix this?

biswa picture biswa · Jul 22, 2013 · Viewed 12.1k times · Source

I am trying to send email using Gmail SMTP. Following is my code.

$mail = new Zend_Mail();
$config = array(
            'ssl'      => 'ssl',
            'port'     => '465',
            'auth'     => 'login',
            'username' => '[email protected]',
            'password' => 'mypassword'
        );

$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$sendNow   = $mail->setBodyHtml($message)
                  ->setFrom('[email protected]', 'abc def')
                  ->addTo($recipient)
                  ->setSubject($subject)
                  ->send($transport);

But the following error occurs. How can make it done?

Fatal error: Uncaught exception 'Zend_Mail_Protocol_Exception' with message 'Unable to find the socket transport 'ssl' - did you forget to enable it when you configured PHP?' in Implementation\trunk\webapp\library\Zend\Mail\Protocol\Abstract.php:277

Answer

shruti picture shruti · Oct 18, 2013

Here is my code for zend mail.....

    $config = array('ssl' => 'tls',
                'auth' => 'login',
                'username' => '[email protected]',
                'password' => 'password');

    $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);

    $mail = new Zend_Mail();
    $mail->setBodyHtml($bodytext);
    $mail->setFrom('[email protected]');
    $mail->addTo($email, $username);
    $mail->setSubject('Profile Activation');
    $mail->send($transport);

And it is working now properly...