2011-06-23 114 views
0

Possible Duplicate:
email zend framwork smtp在zend中使用gmail smtp发送电子邮件?

我有以下配置:

smtp.type = Zend_Mail_Transport_Smtp 
smtp.smtpServer = "smtp.gmail.com" 
smtp.username = "[email protected]" 
smtp.password = "dddd" 
smtp.email = "[email protected]" 
smtp.port = "587" 
smtp.ssl = "tls" 
smtp.auth = "login" 

我收到以下错误:

5.7.0 Must issue a STARTTLS command first. 74sm813723wem.41 

我的代码:

public function sendEmail($mailData, $bootstrap = null) { 

     // Get SMTP server configurations 
     if ($bootstrap == null) { 
      $front = Zend_Controller_Front::getInstance(); 
      $bootstrap = $front->getParam('bootstrap'); 
     } 
     $smtpSettings = $bootstrap->getOption('smtp'); 

     print_r($smtpSettings); 

     // Only pass username password settings if the authentication is required. 
     if ($smtpSettings['auth'] == 'login') { 

      $config = array('ssl' => $smtpSettings['ssl'], 
         'username' => $smtpSettings['username'], 
         'password' => $smtpSettings['password']); 

      $transport = new Zend_Mail_Transport_Smtp($smtpSettings['smtpServer'], $config); 
     } else { 
      $transport = new Zend_Mail_Transport_Smtp($smtpSettings['smtpServer']); 
     } 

     $mail = new Zend_Mail('utf-8'); 

     try { 

      if ($mailData['user'] == true) { 
       $mail->setFrom($mailData['from'], $mailData['fromName']); 

      } else { 
        $mail->setFrom($smtpSettings['email'], "eCHDP"); 
      } 

      // Do we have a single reciepent or multiple receipents? 
      if (!is_array($mailData['to'])) { 
       $mail->addTo($mailData['to'] , $mailData['toName']); 
      } else { 
       // We have multiple receipents. Add all of them. 
       foreach ($mailData['to'] as $id => $value) { 
        $mail->addTo($value , $mailData['toName'][$id]); 
       } 
      } 

      $mail->setSubject($mailData['subject']); 
      $mail->setBodyHtml($mailData['body']); 

      // If attachment found then attach 
      if ($mailData['attachment']) { 
       $attach = new Zend_Mime_Part(file_get_contents($mailData['attachment'])); 
       $attach->type = 'application/pdf'; 
       $attach->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; 
       $attach->filename = 'Invoice.pdf'; 
       $mail->addAttachment($attach); 
      } 

      $mail->send($transport); 

      return true; 

     } catch (Exception $e) { 
      echo "Error sending Email : "; 
      $logger = Zend_Registry::get('Logger'); 
      $logger->err($e->getMessage()); 
      echo $e->getMessage() . "\n\n\n"; 
      return false; 
     } 

    } 

有人能猜到是什么错误?如果需要,我也可以发布代码。

感谢

+1

我猜你必须首先发出一个STARTTLS命令;)不,认真:你正在使用'ssl = ssl',你应该尝试'ssl = tls' - 这是两种不同的方法来保证连接到服务器。 – Piskvor

回答

8

这是从我们的application.ini

resources.mail.transport.type = Zend_Mail_Transport_Smtp 
resources.mail.transport.host = "smtp.gmail.com" 
resources.mail.transport.port = 587 
resources.mail.transport.auth = "login" 
resources.mail.transport.username = "[email protected]" 
resources.mail.transport.password = "password" 
resources.mail.transport.ssl = "tls" 

它 “只是工作(TM)”!

+0

好的。让我试试这个,但是你在哪里使用'resources.mail.transport.type'? – Awan

+0

Ehh .. in application.in :)您是否仅使用Zend_Mail或者它是一个全面的ZF站点? http://framework.zend.com/manual/en/learning.quickstart.html 无论如何,您应该可以在您的规格中使用我们的配置值。 – Phliplip

+0

当Zend MVC与邮件传输一起使用时,邮件资源简单地自动对Zend_Mail进行自动回复 –

1

你可以尝试使用:ssl = tlsport = 587

+0

同样的错误.. :) – Awan

相关问题