无法使用CodeIgniter的电子邮件库

时间:2015-06-20 23:59:29

标签: php codeigniter email smtp gmail

我正在尝试使用CodeIgniter的电子邮件库发送电子邮件。这是我写的代码。

        $email_config = array(
            'protocol'  => 'smtp',
            'smtp_host' => ' ssl://smtp.gmail.com',
            'smtp_port' => '465',
            'smtp_user' => 'shamir.towsif@gmail.com',
            'smtp_pass' => '**********',
            'mailtype'  => 'html',
            'newline'   => "\r\n",
            'charset' => 'iso-8859-1',
            "wordwrap" => true
        );

    $this->CI->load->library('email', $email_config);
    $this->CI->email->from('shamir.towsif@gmail.com', 'invoice');
    $this->CI->email->to('shamir.towsif@gmail.com', "User");
    $this->CI->email->subject('Invoice');
    $this->CI->email->message('Test');
    $this->CI->email->send();
    echo $this->CI->email->print_debugger();

错误:这是我收到的错误。

  

遇到以下SMTP错误:0 php_network_getaddresses:   getaddrinfo失败:名称或服务未知无法发送数据:   AUTH LOGIN无法发送AUTH LOGIN命令。错误:无法发送   data:MAIL FROM:from:遇到以下SMTP错误:   无法发送数据:RCPT TO:to:以下SMTP错误   遇到:无法发送数据:DATA数据:以下SMTP   遇到错误:无法发送数据:User-Agent:CodeIgniter   日期:2015年6月21日星期日05:52:56 +0600来自:“invoice”返程路径:至:   shamir.towsif@gmail.com主题:=?iso-8859-1?Q?发票?=回复:   “shamir.towsif@gmail.com”X-Sender:shamir.towsif@gmail.com X-Mailer:   CodeIgniter X-Priority:3(正常)消息ID:   < 5585fcd8c63f7@gmail.com> Mime版本:1.0内容类型:   多部分/替代; boundary =“B_ALT_5585fcd8c643b”这是一个   MIME格式的多部分消息。您的电子邮件申请可能不会   支持这种格式。 --B_ALT_5585fcd8c643b Content-Type:text / plain;   charset = iso-8859-1 Content-Transfer-Encoding:8bit测试   --B_ALT_5585fcd8c643b Content-Type:text / html; charset = iso-8859-1 Content-Transfer-Encoding:quoted-printable Test   --B_ALT_5585fcd8c643b--无法发送数据:。

     

遇到以下SMTP错误:无法使用发送电子邮件   PHP SMTP。您的服务器可能未配置为使用此服务器发送邮件   方法。 User-Agent:CodeIgniter日期:Sun,2015年6月21日05:52:56 +0600   来自:“发票”退货路径:    收件人:shamir.towsif@gmail.com主题:   =?iso-8859-1?Q?Invoice?=回复:“shamir.towsif@gmail.com”X-Sender:shamir.towsif@gmail.com X-Mailer:   CodeIgniter X-Priority:3(正常)消息ID:   < 5585fcd8c63f7@gmail.com>哑剧版:1.0

     

内容类型:multipart / alternative;边界= “B_ALT_5585fcd8c643b”

     

这是MIME格式的多部分邮件。您的电邮申请表   可能不支持这种格式。

     

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

     

测试

     

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

     

测试

     

- B_ALT_5585fcd8c643b -

问题:我曾经能够发送电子邮件。然后我重新安装了我的操作系统和灯服务器,现在我不能。我做错了什么?

1 个答案:

答案 0 :(得分:2)

我在CI中使用sendmail发送电子邮件。在使用发送邮件之前,您必须在CI中进行一些配置。

首先,转到system / libraries / Email.php并更改以下内容

class CI_Email {

  var   $useragent      = "CodeIgniter";
  var   $mailpath       = "/usr/sbin/sendmail"; // Sendmail path
  var   $protocol       = "sendmail";   // mail/sendmail/smtp
  var   $smtp_host      = "mail.blah-blah.com";     // SMTP Server.  


  .....
}

然后我制作一个发送电子邮件的方法。

public function send_mail($email, $subject, $message){
        //$this->load->library( 'email' );
        $this->email->from( 'no-reply@blah-blah.com', 'blah-blah.com' );
        $this->email->to( $email);
        $this->email->subject( $subject );
        $this->email->message( $message );
        $this->email->send();

        echo $this->email->print_debugger();

    }

这就是全部。您现在可以使用send_mail方法发送电子邮件。

相关问题