Zend_Log与邮件

时间:2009-07-22 12:18:04

标签: zend-framework

是否有人使用Zend_Log成功发送邮件(SMTP GOOGLE)。我发现此http://framework.zend.com/manual/en/zend.log.writers.html 第32.2.4章。写入电子邮件,但默认情况下它使用mail(),但我想使用SMTP.So到现在为止我的代码看起来像这样:

  $mailconf = array('ssl'=>'ssl',
            'auth' => 'login',
                    'username' => 'mymail@gmail.com',
                    'password' => 'mypass',
                    'port'=>'465');     
    $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $mailconf);                


    $mail = new Zend_Mail();
    $mail->setFrom('from.website@example.com')
         ->addTo('mysecondmail@site.com');

    $writer = new Zend_Log_Writer_Mail($mail);
    // On fixe le sujet du mail
    $writer->setSubjectPrependText('Important Log Events');

    // Only email warning level entries and higher.
    $writer->addFilter(Zend_Log::WARN);

    $loggerZendMail = new Zend_Log();
    $loggerZendMail->addWriter($writer);

    $loggerZendMail->log('unable to connect to database',Zend_Log::WARN);

我收到了这个错误:

  

致命错误:在C:\ wamp \ www \ zf_log \ Zend \ Log \ Writer \ Mail.php中显示消息'无法发送邮件'的未捕获异常'Zend_Log_Exception':256堆栈跟踪:#0 C:\ wamp \ www \ zf_log \ Zend \ Log.php(84):Zend_Log_Writer_Mail-> shutdown()#1 C:\ wamp \ www \ zf_log \ Zend \ Controller \ Action.php(512):Zend_Log-> __ destruct()# 2 C:\ wamp \ www \ zf_log \ Zend \ Controller \ Action.php(512):IndexController-> indexAction()#3 C:\ wamp \ www \ zf_log \ Zend \ Controller \ Dispatcher \ Standard.php(288) ):Zend_Controller_Action-> dispatch('indexAction')#4 C:\ wamp \ www \ zf_log \ Zend \ Controller \ Front.php(945):Zend_Controller_Dispatcher_Standard-> dispatch(Object(Zend_Controller_Request_Http),Object(Zend_Controller_Response_Http)) #5 C:\ wamp \ www \ zf_log \ index.php(30):Zend_Controller_Front-> dispatch()#6 {main}抛出C:\ wamp \ www \ zf_log \ Zend \ Log \ Writer \ Mail.php在第256行

有什么建议吗?

3 个答案:

答案 0 :(得分:2)

您需要设置Zend_Mail的传输使用

示例:


Zend_Mail::setDefaultTransport($transport);

答案 1 :(得分:0)

我会检查服务器上是否启用了SMTP。

答案 2 :(得分:0)

使用TLS而不是SSL也检查端口587是否正常工作

所以下面的配置应该有效

$mailconf = array('ssl'=>'tls', 'auth' => 'login', 'username' => 'mymail@gmail.com', 'password' => 'mypass', 'port'=>'587');