【问题标题】:CodeIgniter - Unable to send email using PHP SMTP only in my own serverCodeIgniter - 无法仅在我自己的服务器中使用 PHP SMTP 发送电子邮件
【发布时间】:2018-09-08 10:37:38
【问题描述】:

我正在使用 CodeIgniter 使用此代码发送电子邮件:

$config['protocol'] = "smtp";
$config['smtp_host'] = "mail.******.com";
$config['smtp_port'] = "25";
$config['smtp_user'] = "****@****.com";
$config['smtp_pass'] = "*****";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['send_multipart'] = \r\n;
$config['crlf'] = "\r\n";

$this->email->initialize($config);
$this->email->set_newline("\r\n");

当我在在线服务器(公共主机)上运行时,它会成功。

但是当我在自己的本地服务器上执行代码时出现以下错误。

Failed to send AUTH LOGIN command. Error: 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter

我的代码或服务器配置是否有任何错误?

【问题讨论】:

  • 你加载了$this->load->library('email');吗?或检查smtp_port587
  • 我把库放在最上面

标签: php codeigniter email


【解决方案1】:

在初始化之前加载库。愿这有帮助

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

 $config['mailtype'] = 'html';
 $config['smtp_host'] = "mail.******.com";
 $config['smtp_port'] = "25";  //465,587
 $config['smtp_user'] = "****@****.com";
 $config['smtp_pass'] = "*****";
 $config['smtp_timeout']='30';
 $config['charset']='utf-8';
 $config['protocol'] = 'smtp';
 $config['wordwrap'] = TRUE;
 $config['newline']  = "\r\n";

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

【讨论】:

    【解决方案2】:

    和你的代码无关,和你邮件服务器的配置有关!或者尝试将端口更改为 587!

    Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method

    【讨论】:

    • 我试过了,然后我得到了这个错误:SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:140770FC:SSL 例程:SSL23_GET_SERVER_HELLO:未知协议
    猜你喜欢
    • 2014-12-18
    • 2012-10-20
    • 2021-06-17
    • 1970-01-01
    • 2016-06-28
    • 2021-10-01
    • 1970-01-01
    相关资源
    最近更新 更多