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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题