Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SMTP邮件未发送-Codeigniter电子邮件库_Php_Codeigniter_Email_Codeigniter 3 - Fatal编程技术网

Php SMTP邮件未发送-Codeigniter电子邮件库

Php SMTP邮件未发送-Codeigniter电子邮件库,php,codeigniter,email,codeigniter-3,Php,Codeigniter,Email,Codeigniter 3,我在通过SMTP协议发送邮件时遇到问题 Welcome.php $this->load->library('email'); $config = array(); $config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.zoho.com'; $config['smtp_user'] = 'support@domain.com'; $config['smtp_pass'] = '**************'; $conf

我在通过SMTP协议发送邮件时遇到问题

Welcome.php

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

$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.zoho.com';
$config['smtp_user'] = 'support@domain.com';
$config['smtp_pass'] = '**************';
$config['smtp_port'] = 465;
$config["smtp_crypto"] = "ssl";

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

$this->email->set_newline("\r\n");
$this->email->from('support@domain.com', 'Support name'); // change it to yours
$this->email->to($to);// change it to yours
$this->email->subject($subject);
$this->email->message($message);

    if($this->email->send())
    {
      echo "Success! - An email has been sent to ".$to;
    }
    else
    { 
      show_error($this->email->print_debugger());
      return false;
    }
}
以下是输出错误:

An Error Was Encountered
220 mx.zohomail.com SMTP Server ready June 29, 2018 5:16:40 AM PDT 

hello: 

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.
Date: Fri, 29 Jun 2018 12:16:40 +0000
From: "Support Name" <support@domain.com>
Return-Path: <support@domain.com>
To: recipent@gmail.com
Subject: =?ISO-8859-1?Q?=43=6F=70=79=20=61=6C=6C=20=74=68=65?=
Reply-To: <support@domain.com>
User-Agent: CodeIgniter
X-Sender: support@domain.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5b36232840595@domain.com>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_5b3623284061c"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_5b3623284061c
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Some


--B_ALT_5b3623284061c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Some Email Description=0A=0A Some Email Description

--B_ALT_5b3623284061c--
遇到错误 220 mx.zohomail.com SMTP服务器准备就绪2018年6月29日太平洋时间上午5:16:40 你好: 遇到以下SMTP错误: 无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。 日期:2018年6月29日星期五12:16:40+0000 发件人:“支持名称” 返回路径: 致:recipent@gmail.com 主题:=?ISO-8859-1?Q?=43=6F=70=79=20=61=6C=6C=20=74=68=65= 答复: 用户代理:CodeIgniter X-Sender:support@domain.com X-Mailer:CodeIgniter X优先级:3(正常) 消息ID: Mime版本:1.0 内容类型:多部分/备选;boundary=“B_ALT_5B362328284061C” 这是MIME格式的多部分消息。 您的电子邮件应用程序可能不支持此格式。 --B_ALT_5B362328284061C 内容类型:文本/纯文本;字符集=ISO-8859-1 内容传输编码:8比特 一些 --B_ALT_5B362328284061C 内容类型:text/html;字符集=ISO-8859-1 内容传输编码:引用可打印 一些电子邮件描述=0A=0A一些电子邮件描述 --B_ALT_5B362328284061C-- 注意:该脚本在本地主机和多个主机上运行良好 其他主机,但不在VPS主机上工作

以下是要记住的事情:

  • 代码很好(在不同的主机中进行了尝试,效果很好)
  • 更改
    $config['protocol']=“smtp”
    $config['protocol']=“sendmail”它可以工作。但我只想通过SMTP协议发送邮件
    
  • 使用Zoho邮件SMTP协议(SMTP.Zoho.com)
  • 已尝试,谷歌SMTP,仍然没有发送。(使用PHPMailer库对凭据进行测试。它正在处理凭据。)

  • 我希望这个代码能正常工作

    $Config = [
      'protocol'  => 'smtp', 
      'smtp_host' => 'smtp.zoho.com', 
      'smtp_port' =>  465, 
      'smtp_user' => 'support@domain.com', 
      'smtp_pass' => '**************', 
      'mailtype'  => 'html', 
      'charset'   => 'utf-8'
    ];
    $this->load->library('email',$config);
    $this->email->set_newline("\r\n");
    $this->email->from('support@domain.com', 'Support name'); // change it to yours
    $this->email->to($to);// change it to yours
    $this->email->subject($subject);
    $this->email->message($message);
    if($this->email->send()){
       echo "Success! - An email has been sent to ".$to;
    }
    else{ 
       show_error($this->email->print_debugger());
       return false;
    }
    
    解决方案: 问题已解决!罪魁祸首是有效主机名反向DNS

    详细信息: 由于配置错误,SMTP在
    7-10秒左右响应。根据,如果我们不指定
    smtp\u超时
    ,它将采用默认值,即
    5秒
    。 因此,我将smtp_超时时间从默认的
    5秒更改为
    10秒,并且可以正常工作


    找出问题所在后,发现SMTP响应缓慢。没有有效的主机名,添加了反向DNS。他补充道。现在它正在按预期工作。现在我删除了
    smtp\u timeout
    字段。它正在工作

    但是,使用相同的凭据,在相同的VPS中尝试使用phpMail。它在那里工作。邮件正在按预期发送。问题只出现在CodeIgniter上。真奇怪,你的配置正确吗?可能您的SMTP服务器没有尝试使用PHPMailer。成功了。脚本也在处理其他人质。。。我百分之百肯定这些证件是正确的。。甚至代码也在某些主机上工作。但是在VPS上,它不起作用。。在codeigniter中是否有发送邮件的要求?你应该看看那些。