无法使用gmail SMTP在Zend中发送电子邮件。出现致命错误:未捕获的异常“ Zend_Mail_Protocol_Exception”。如何解决这个问题?

问题描述 投票:3回答:2

我正在尝试使用Gmail SMTP发送电子邮件。以下是我的代码。

$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);

但会出现以下错误。如何使它做什么?

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

php zend-framework zend-mail
2个回答
7
投票

这是我的zend邮件代码.....

    $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);

并且现在可以正常使用...


2
投票

您为Gmail配置的设置与我的设置不同。这是我使用的:

$config = array(
            'host' => 'smtp.gmail.com',
            'port' => 587,
            'ssl' => 'tls',
            'auth' => 'login',
            'username' => '*****',
            'password' => '*****',
        );

请注意'ssl'和'port'的区别。

© www.soinside.com 2019 - 2024. All rights reserved.