2017-08-02 125 views
0

我使用電子郵件類笨發送電子郵件扔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)給了我相同的警告和錯誤。

任何一個人知道我哪裏出錯了?

+0

是否啓用Gmail上的'讓不太安全app'?原因是谷歌需要驗證,如果你真的允許這種類型的行動,所以我相信配置它會解決你的問題。 - https://support.google.com/accounts/answer/6010255?hl=zh-CN – KaoriYui

+0

@KaoriYui這不會導致Connection超時錯誤,而是Auth錯誤。 –

+0

是的,我有。它正在我的本地主機上工作 –

回答

0

檢查生產服務器上的php.ini文件。 如果您在php.ini中有;extension=php_openssl.dll,請將其更改爲extension=php_openssl.dll(刪除昏迷,然後重新啓動apache或nginx)。

+0

我在共享主機上,所以我無法查看php.ini文件並對其進行更改:( –

+0

您可以與您的提供商聯繫,並要求他們提供呻吟聲 –

1

端口587被髮送smtp連接的爸爸阻止,根據您的要求使用以下端口之一作爲指定。

非SSL - 80,3535,25

SSL - 465

https://www.godaddy.com/help/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account-319

+0

感謝您的回覆但它將錯誤號碼更改爲111這裏是錯誤 遇到以下SMTP錯誤:111連接被拒絕 無法使用PHP SMTP發送電子郵件您的服務器可能未配置爲使用此方法發送郵件 –

+0

您嘗試了端口25? –

+0

是的,我已經嘗試過所有:'( –

相關問題