微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 发送邮件的SMTP协议不能与codeigniter一起使用

$config = Array(
'protocol' => 'smtp','smtp_host' => 'smtp.gmail.com','smtp_port' => 465,'smtp_user' => 'XXXX@XXXX.com','smtp_pass' => 'XXXX','mailtype'  => 'html','charset'   => 'iso-8859-1'
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");

$this->email->from('xxxxx@xxx.com','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(连接被拒绝).

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

解决方法

我正在使用这种方式,它对我有用:

$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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐