php - 用于发送邮件的 SMTP 协议(protocol)不适用于 codeigniter

标签 php codeigniter smtp fsockopen

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

关于php - 用于发送邮件的 SMTP 协议(protocol)不适用于 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42141757/

相关文章:

php - 从数据库中选择不同的值

javascript - PHP - 如果用户退出网页则取消链接文件?

smtp - 使用 telnet 总是拒绝连接

smtp - IIS smtp 消息卡在 inetpub/mailroot/queue 中

php - http请求到同一网络的其他计算机失败

php - 包含 AND 子字符串条件的 WHERE 子句

php - 如何将图像与数据库中的记录链接起来?

php - 从范围中选择数字

php - 模型类应该代表一个实体还是返回它

java - 提高发送java邮件的速度