2012-05-03 63 views
0

我收到了用于发送基本电子邮件的代码。但对于SMTP,我不能完善这个:使用cakephp通过smtp发送电子邮件

 function send(){ 

      $this->Email->smtpOptions = array(
       'port'=>'465', 
       'timeout'=>'30', 
       'host' => 'ssl://smtp.gmail.com', 
       'username'=>'[email protected]', 
       'password'=>'mypassword', 
      ); 

     $this->Email->delivery='smtp'; 

      $this->Email->send = 'debug'; 

      $this->Email->to = '[email protected]'; 
     $this->Email->subject = 'hurrah'; 
//  $this->Email->replyTo = '[email protected]'; 
     $this->Email->from = 'Charmaine Khay Sorila<[email protected]>'; 
     //$this->Email->send('Here is the body of the email Chams Email Test'); 
     //Set the body of the mail as we send it. 
     //Note: the text can be an array, each element will appear as a 
     //seperate line in the message body. 

     if ($this->Email->send()) { 
      $this->Session->setFlash('Simple email sent'); 
     } else { 
      $this->Session->setFlash('Simple email not sent'); 
      $this->set('smtp_errors', $this->Email->smtpError); 
     } 
     } 

    } 

我得到这个工作,而不$这个 - >的电子邮件 - >快递=“SMTP”;但是当我加入这一行,没有电子邮件,可以在所有发送:(

+0

您正在使用调试选项,尝试将其删除 – yossi

+0

同样的事情yossi ..实际发生的是页面加载了几秒钟,然后它不会发送任何电子邮件... :( – Charmie

+0

第一:你得到了什么错误? – yossi

回答

0

如果你不希望实际发送电子邮件,而是想测试出来的功能,你可以使用下面的发送选项:

Copy to Clipboard 
$this->Email->delivery = 'debug'; 
+0

那里。我得到它的工作,但事情是..我检查,如果它真的是用于传递我的邮件,所以我故意键入的密码错误,但它仍然发送了一封电子邮件的SMTP ...“。 – Charmie

相关问题