dongrou839975 2016-01-29 07:16
浏览 354

CodeIgniter电子邮件发送错误

I am trying to send email with CodeIgniter here is my code

function sendmail()
    {
            // Set SMTP Configuration
            $emailConfig = array(
               'protocol' => 'smtp',
                'smtp_host' => 'TLS://smtp.googlemail.com',
                'smtp_port' => 587,
                'smtp_user' => 'email@gmail.com',
                'smtp_pass' => '******',
                'mailtype'  => 'html',
                'charset'   => 'iso-8859-1'
            );

            // Set your email information
            $from = array('email' => 'frommail@gmail.com', 'name' => 'Your Name');
            $to = array('mymail@gmail.com');
            $subject = 'Your gmail subject here';

            $message = 'Type your gmail message here';
            // Load CodeIgniter Email library
            $this->load->library('email', $emailConfig);

            // Sometimes you have to set the new line character for better result
            $this->email->set_newline("rn");
            // Set email preferences
            $this->email->from($from['email'], $from['name']);
            $this->email->to($to);

            $this->email->subject($subject);
            $this->email->message($message);
            // Ready to send email and check whether the email was successfully sent

            if (!$this->email->send()) {
                // Raise error message
                show_error($this->email->print_debugger());
            }
            else {
                // Show success notification or other things here
                echo 'Success to send email';
            }

    }

but it gives me this type of error

The following SMTP error was encountered: 110 Connection timed out Unable to send data: AUTH LOGIN Failed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM:

from:

The following SMTP error was encountered: Unable to send data: RCPT TO:

to:

The following SMTP error was encountered: Unable to send data: DATA

data:

The following SMTP error was encountered: Unable to send data: User-Agent: CodeIgniter Date: Fri, 29 Jan 2016 06:59:14 +0000 From: "Alex Tester" Return-Path: To: coderjack9@gmail.com Subject: =?iso-8859-1?Q?Email_Test?= Reply-To: "alextester1003@gmail.com" X-Sender: alextester1003@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <56ab0dc2af7ad@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_56ab0dc2af809" This is a multi-part message in MIME format. Your email application may not support this format. --B_ALT_56ab0dc2af809 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Testing the email class. --B_ALT_56ab0dc2af809 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Testing the email class. --B_ALT_56ab0dc2af809-- Unable to send data: .

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.

  • 写回答

2条回答 默认 最新

  • donglou8371 2016-01-29 07:33
    关注
     $this->load->library('email');
      $this->load->library('user_agent');    
      $this->email->from(from@gmail.com);
      $this->email->to(to@gmail.com);   
      $this->email->cc(cc@gmail.com); 
       $this->email->subject('sub');$this->email->message($messages);   
     $this->email->send();
    

    Note: the mail cannot sent localhost. if your try live sites.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算