Codeigniter发送谷歌邮件错误

时间:2014-01-18 03:00:36

标签: php codeigniter email ssl

我在主机Cpanel中使用Codeignter。在本地我可以通过谷歌帐户发送电子邮件,但在主机Cpanel上它出错。 这是我的配置:

$ci = get_instance();

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

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

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

$config['smtp_port'] = 465;

$config['smtp_user'] = "xxx@gmail.com"; 

$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 
.....

请帮帮我! 对不起我的英语不好

3 个答案:

答案 0 :(得分:1)

#1 确保您在Apache中有 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']    = '*****developer@gmail.com'; // 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('trimantradeveloper@gmail.com', 'TSS DEV');
$this->email->to('trimantra@trimantra.com'); 
$this->email->cc('trimantra@gmail.com'); 

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

$this->email->send();

答案 1 :(得分: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();

答案 2 :(得分:0)

确保你的服务器的apache已经启用了ssl模块。最可能是它的原因。或者你可以做其他的方式。检查删除谷歌的smtp ssl方法。如果你这样做你想要更改smtp端口表格465至587