2011-06-10 69 views
9

我希望使用Gmail的smtp發送用戶信息到註冊的電子郵件。gmail smtp不工作在我的託管使用codeigniter框架

我使用的代碼在我的本地主機上正常工作,但是當我更改爲共享主機時,出現了以下錯誤。

A PHP Error was encountered 
Severity: Warning 

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out) 

Filename: libraries/Email.php 

Line Number: 1652 

A PHP Error was encountered 
Severity: Warning 

Message: fwrite(): supplied argument is not a valid stream resource 

Filename: libraries/Email.php 

Line Number: 1795 

.... (more error msg here) 

An Error Was Encountered 
The following SMTP error was encountered: 110 Connection timed out 
Unable to send data: AUTH LOGIN 
Failed to send AUTH LOGIN command. Error: 
Unable to send data: MAIL FROM: 


from: 
The following SMTP error was encountered: 
Unable to send data: RCPT TO: 

to: 
The following SMTP error was encountered: 
Unable to send data: DATA 

.... (more error msg here) 

這裏是我的電子郵件配置

$pass = $this->generatePassword('6'); 

$config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_timeout'=>'30', 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => 'mypassword', 
    'mailtype' => 'html', 
    'charset' => 'iso-8859-1' 
); 
$this->load->library('email', $config); 
$this->email->set_newline("\r\n"); 

$this->email->from('[email protected]','Title'); 
$this->email->to($this->input->post('email')); 

$this->email->subject('Subject here'); 
$this->email->message('Your login username is '.$this->input->post('username').'<br/>'.'Password is '.$pass); 

if (!$this->email->send()){ 
    show_error($this->email->print_debugger()); 
}else{ echo 'YEAH!!!';} 

我嘗試檢查我的份額託管的OpenSSL是否被啓用。我發現這個

OpenSSL的 OpenSSL的支持啓用
的OpenSSL版本的OpenSSL 0.9.8e - FIPS的RHEL5 2008

7月01日如果OpenSSL是啓用。仍然會是我的代碼中的錯誤?

我開始感到沮喪,使用我的本地主機開發,當它上傳到共享主機,它出來機智很多錯誤。

任何幫助將不勝感激! thx in advanced

回答

15

看起來像共享主機中的ur ssl端口是關閉的, 使用此代碼來檢查它是否打開。

$fp = fsockopen("www.google.com", 80, &$errno, &$errstr, 10); // work fine 
if (!$fp) 
    echo "www.google.com - $errstr ($errno)<br>\n"; 
else 
    echo "www.google.com - ok<br>\n"; 


$fp = fsockopen("smtp.gmail.com", 465, &$errno, &$errstr, 10); // NOT work 
if (!$fp) 
    echo "smtp.gmail.com 465 - $errstr ($errno)<br>\n"; 
else 
    echo "smtp.gmail.com 465 - ok<br>\n"; 


$fp = fsockopen("smtp.gmail.com", 587, &$errno, &$errstr, 10); // NOT work 
if (!$fp) 
    echo "smtp.gmail.com 587 - $errstr ($errno)<br>\n"; 
else 
    echo "smtp.gmail.com 587 - ok<br>\n"; 
+1

嗨,TQ你的答案。 我剛問過我的共享主機提供商。他們說他們沒有啓用端口465,現在他們啓用它。我嘗試使用Joomla 1.6來測試它現在可用的gmail smtp。但我嘗試2在我的codeigniter網站測試它,當我點擊註冊按鈕時,我的網站沒有響應。和頁面就像繼續加載...這是否意味着我Nid 2清除任何cookie或重置任何東西? – 2011-06-11 01:17:22

+0

好的。我關閉瀏覽器並重新打開。現在它可以工作。謝謝 !! – 2011-06-11 01:25:45

+0

thanx代碼 – 2012-06-28 08:49:03

4

有較新的PHP版本 更新測試腳本:

<?php 

    $fp = fsockopen("www.google.com", 80, $errno, $errstr, 10); // work fine 
    if (!$fp) 
     echo "www.google.com - $errstr ($errno)<br>\n"; 
    else 
     echo "www.google.com - ok<br>\n"; 


    $fp = fsockopen("smtp.gmail.com", 465, $errno, $errstr, 10); // NOT work 
    if (!$fp) 
     echo "smtp.gmail.com 465 - $errstr ($errno)<br>\n"; 
    else 
     echo "smtp.gmail.com 465 - ok<br>\n"; 


    $fp = fsockopen("smtp.gmail.com", 587, $errno, $errstr, 10); // NOT work 
    if (!$fp) 
     echo "smtp.gmail.com 587 - $errstr ($errno)<br>\n"; 
    else 
     echo "smtp.gmail.com 587 - ok<br>\n"; 



?>