3

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

$mail = new Zend_Mail();
$config = array(
            'ssl'      => 'ssl',
            'port'     => '465',
            'auth'     => 'login',
            'username' => 'username@gmail.com',
            'password' => 'mypassword'
        );

$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$sendNow   = $mail->setBodyHtml($message)
                  ->setFrom('username@gmail.com', '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

4

2 回答 2

7

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

    $config = array('ssl' => 'tls',
                'auth' => 'login',
                'username' => 'your@gmail.com',
                'password' => 'password');

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

    $mail = new Zend_Mail();
    $mail->setBodyHtml($bodytext);
    $mail->setFrom('your@gmail.com');
    $mail->addTo($email, $username);
    $mail->setSubject('Profile Activation');
    $mail->send($transport);

它现在工作正常......

于 2013-10-18T11:41:46.310 回答
2

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

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

请注意“ssl”和“端口”的区别。

于 2013-08-07T10:07:04.183 回答