2010-12-12 108 views
3

我有一個電子郵件發送蛋糕的問題。我的方法是這樣的:CakePHP SMTP電子郵件語法錯誤

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

     $this->Email->from = "[email protected]"; 
     $this->Email->to  = "[email protected]"; 
     $this->Email->subject = "Test"; 
     $this->Email->sendAs = "text"; 

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

     $this->Email->send('Hello message body!'); 

但是,當我嘗試發送電子郵件我得到:

555 5.5.2 Syntax error. l3sm512374fan.0 

我需要做什麼才能chnage這個工作?

感謝

回答

10

RFC2821,到谷歌的SMTP服務器似乎是一個堅持己見,電子郵件地址的格式應以下列方式:

Recipient Name <[email protected]> 
-or- 
<[email protected]> 

這樣做對雙方fromto地址,你應該很好去。如果你沒有用戶名,那麼你可以重複電子郵件:

$this->Email->to = "[email protected] <[email protected]>"; 
-or- 
$this->Email->to = "<[email protected]>"; 
+0

這工作,謝謝 – Elwhis 2010-12-12 13:56:21

+1

這不適用於我。同樣的問題...有沒有任何更新或任何其他原因,爲什麼這種語法錯誤可能會發生? – BWelfel 2011-04-08 05:02:13

+0

你應該真的發佈一些代碼來幫助我們找出問題出在哪裏。還包括您正在使用的CakePHP版本。 – RabidFire 2011-04-10 10:47:37