【问题标题】:CodeIgniter set smtp email globally for version 2.1.2CodeIgniter 为 2.1.2 版本全局设置 smtp 电子邮件
【发布时间】:2018-02-15 10:08:53
【问题描述】:

在我的一个项目中 CodeIgniter 版本是 2.1.2

这里的系统库邮件是从sendmail发送的

但我想在不使用 sendemail 的情况下全局设置 smtp,并且不想在每个地方发送电子邮件之前设置配置参数。

为了克服这个问题,我在路径“application\config\email.php”上添加了 email.php 文件

添加以下参数值

$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = 'youremailaddress@gmail.com';
$config['smtp_pass'] = 'yourpassword';
$config['smtp_port'] = 465; 
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;

但它给了我如下错误 遇到以下 SMTP 错误:

Failed to send AUTH LOGIN command. Error: 
from: 
The following SMTP error was encountered: 
to: 
The following SMTP error was encountered: 
data: 
The following SMTP error was encountered: 

The following SMTP error was encountered: 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

谁能帮我解决这个问题或以任何其他方式以全局方式设置 smtp 吗?

我将不胜感激最佳答案。

【问题讨论】:

  • 所以有几个问题:1)如果直接应用配置,它是否有效? IE。什么时候构建 Email 类? 2)您是否自动加载配置文件? (即 application/config/autoload.php >> config ??)
  • 感谢您的回复 1) 不,当我直接应用配置时它不起作用 2) 是的,我已经在 autoload.php 中加载了 email.php 文件,例如 $autoload['config'] = array("email ");

标签: php codeigniter


【解决方案1】:

试试这个...

'protocol'  => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port'     => 587,
'smtp_user'     => 'youremail',
'smtp_pass'     => 'yourpass',
'mailtype'      => 'html',
'smtp_crypto'   => 'tls',
'charset'       => 'iso-8859-1',
'clrf'      => "\r\n",
'newline'   => "\r\n",

我的连接所需的主要参数。

【讨论】:

  • 拜托,你能告诉我把这个放在哪里吗?这里 -application\config\email.php ?
猜你喜欢
  • 2014-06-07
  • 2019-02-11
  • 2018-12-08
  • 2015-11-10
  • 2014-02-15
  • 1970-01-01
  • 2013-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多