2012-05-18 81 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

相关问题