我使用電子郵件類笨發送電子郵件扔Gmail的SMTP 這是我此設置:使用SMTP的Gmail Codeignator發送電子郵件的工作地方,但給人的主機上的錯誤
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['wordwrap'] = TRUE;
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = '[email protected]'; // I write my correct email here
$config['smtp_pass'] = 'xxxxxxxxx'; // I write my correct password here
$config['smtp_port'] = 587;
$config['smtp_crypto'] = "tls";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$this->email->initialize($config);
$this->email->from('[email protected]', 'My Name');
$this->email->to('[email protected]'); // I write onther email here
$this->email->subject('test gmail smtp');
$this->email->message('success :)');
if (!$this->email->send()) {
echo $this->email->print_debugger();
}
我已經嘗試過了上我的本地機器的代碼工作正常,所有的電子郵件都已收到。我已經上傳到我的GoDaddy的主機我的腳本 後,它給了我這樣的警告: -
fsockopen(): unable to connect to smtp.gmail.com:587 (Connection timed out)
和電子郵件print_debugger();
打印此錯誤: -
The following SMTP error was encountered: 110 Connection timed out Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
我試圖在另一臺主機上運行此代碼( Bluehost)給了我相同的警告和錯誤。
任何一個人知道我哪裏出錯了?
是否啓用Gmail上的'讓不太安全app'?原因是谷歌需要驗證,如果你真的允許這種類型的行動,所以我相信配置它會解決你的問題。 - https://support.google.com/accounts/answer/6010255?hl=zh-CN – KaoriYui
@KaoriYui這不會導致Connection超時錯誤,而是Auth錯誤。 –
是的,我有。它正在我的本地主機上工作 –