2017-02-09 171 views
4
$config = Array(
'protocol' => 'smtp', 
'smtp_host' => 'smtp.gmail.com', 
'smtp_port' => 465, 
'smtp_user' => '[email protected]', 
'smtp_pass' => 'XXXX', 
'mailtype' => 'html', 
'charset' => 'iso-8859-1' 
); 
$this->load->library('email', $config); 
$this->email->set_newline("\r\n"); 

$this->email->from('[email protected]', 'xxxx'); 
$this->email->to($email); 

$this->email->subject('Hi'); 
$this->email->message('Hi'); 

if($this->email->send()) 
{ 
echo 'Your email was sent.'; 
} 

else 
{ 
show_error($this->email->print_debugger()); 
} 

但它显示错误消息:fsockopen():无法连接到smtp.gmail.com:465(连接被拒绝)。SMTP协议发送邮件不与codeigniter

我在这里看到了解决方案Sending mail with CodeIgniter using SMTP protocol not working但它不工作,我无法找到php.ini。

+0

你在本地尝试吗? –

+0

在你的本地服务器上找到php.in安装的驱动器/ php/php.ini或者你可以找到它进入我的电脑,然后在搜索框中按ctrl + f编写php.ini并查看结果 –

+0

@parvez不,我不是在本地这就是为什么我的电脑无法找到它的主机。 –

回答

0

我使用这种方式,它为我工作:

$config = array(
     'protocol' => 'smtps', 
     'smtp_host' => 'ssl://smtps.googlemail.com', 
     'smtp_user' => DONOT_EMAIL, 
     'smtp_pass' => EMAIL_PASSWORD, 
     'smtp_port' => '465', 
     'mailtype' => 'html', 
     'smtp_timeout' => '4', 
     'newline' => "\r\n" 
    ); 

此代码我用于服务器端。 确保每次使用本地或服务器中的邮件功能。初始化如下:

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