简体   繁体   中英

CodeIgniter email sending error

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.

 $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.

User this

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.

$result = $this->email->send();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM