2011-06-23 17 views
0

Possible Duplicate:
email zend framwork smtpzendの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

OK。これを試してみましょう。しかし、この '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 = tlsまたはport = 587

+0

同じエラー.. :) – Awan

関連する問題