2014-01-18 111 views
0

我在主機Cpanel中使用Codeignter。在本地我可以通過谷歌帳戶發送電子郵件,但在主機Cpanel它錯誤。 這是我的配置:Codeigniter發送谷歌郵件錯誤

$ci = get_instance(); 

$ci->load->library('email'); 

$config['protocol'] = "smtp"; 

$config['smtp_host'] = "ssl://smtp.gmail.com"; 

$config['smtp_port'] = 465; 

$config['smtp_user'] = "[email protected]"; 

$config['smtp_pass'] = "xxx"; 

$config['charset'] = "utf-8"; 

$config['mailtype'] = "html"; 
$config['newline'] = "\r\n"; 

$ci->email->initialize($config); 

Openssl在主機上啓用。

這是錯誤警報:

..... 
Message: fsockopen() ...: unable to connect to ssl://smtp.gmail.com:465 
..... 

請幫幫我! 對不起我的英語不好

+0

'ci =&get_instance' –

回答

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

// Set to, from, message, etc. 

$result = $this->email->send(); 
+0

感謝您的幫助!我會嘗試這種方式,但它也不適合我。我在谷歌搜索非常多,但沒有解決方案 – user2424766

1

#1確保您有阿帕奇ssl_module並在php.ini中打開或啓用allow_url_fopen選項

#2請確保您有在Gmail設置中啓用POP3

#3如果你代理服務器或防火牆啓用網絡內的工作;確保你有想要的PORT(465)打開。

試試這個自己測試過的代碼。

$config['useragent'] = 'CodeIgniter'; 
$config['protocol']  = 'smtp'; 
$config['smtp_host'] = 'ssl://smtp.googlemail.com'; 
$config['smtp_user'] = '*****[email protected]'; // Your gmail id 
$config['smtp_pass'] = '**********'; // Your gmail Password 
$config['smtp_port'] = 465; 
$config['wordwrap']  = TRUE;  
$config['wrapchars'] = 76; 
$config['mailtype']  = 'html'; 
$config['charset']  = 'iso-8859-1'; 
$config['validate']  = FALSE; 
$config['priority']  = 3; 
$config['newline']  = "\r\n"; 
$config['crlf']   = "\r\n"; 

$this->load->library('email'); 
$this->email->initialize($config); 

$this->email->from('[email protected]', 'TSS DEV'); 
$this->email->to('[email protected]'); 
$this->email->cc('[email protected]'); 

$this->email->subject('Email Test'); 
$this->email->message('Testing the email class.');  

$this->email->send(); 
+0

感謝您的幫助!我會試着展示你的結果 – user2424766

0

確保服務器的阿帕奇已經在SSL module.Most啓用大概也可以是reason.Or你可以做其他的方式around.Check移除谷歌的SMTP SSL method.If你做,你要更改smtp端口窗體465到587

+0

非常感謝你! – user2424766