2012-05-18 149 views
1

我正在查看cakephp電子郵件組件的第一次。我從我的本地主機發送電子郵件這樣的:無法使用gmail smtp從本地主機發送電子郵件?

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


    $this->Email->delivery = 'smtp'; 
    $this->Email->from = "[email protected]"; 
    $this->Email->to = "[email protected]"; 
    $this->Email->subject = "Subject"; 
    $this->Email->sendAs = 'html'; 
    $this->Email->lineLength = 255; 
    $body = "<h1>This is body</h1>"; 
    $this->Email->send($body); 

它不發送任何電子郵件,甚至沒有表現出任何差錯。

有什麼遺漏嗎?

感謝

+0

退房谷歌帳戶啓用? – Sergey

回答

2

Gmail的SMTP服務器需要SSL,如果我沒有記錯。

嘗試

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

我已經嘗試過,但沒有發送。我刪除了它,因爲我的本地主機上沒有安裝ssl。 – Awan

+0

請閱讀http://support.google.com/mail/bin/answer.py?hl=zh_CN&answer=13287 - 必須使用SSL來使用GMail SMTP服務器。 Quote:「如果您的客戶端不支持SMTP4身份驗證,您將無法使用Gmail地址通過客戶端發送郵件。」 – Gavin

+0

@Gavin固定代碼,請參閱編輯的代碼。 – Ritesh

2

主機應該是:用於SMTP ssl://smtp.gmail.com

+0

我曾嘗試過,但沒有發送。我刪除了它,因爲我的本地主機上沒有安裝ssl。 – Awan

+1

您是否試圖在php.ini中取消對'extension = php_openssl.dll'的註釋? – magnetik

相關問題