1
votes

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 protected]',
                'smtp_pass' => '******',
                'mailtype'  => 'html',
                'charset'   => 'iso-8859-1'
            );

            // Set your email information
            $from = array('email' => '[email protected]', 'name' => 'Your Name');
            $to = array('[email protected]');
            $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: [email protected] Subject: =?iso-8859-1?Q?Email_Test?= Reply-To: "[email protected]" X-Sender: [email protected] X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <[email protected]> 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

2 Answers

0
votes
 $this->load->library('email');
  $this->load->library('user_agent');    
  $this->email->from([email protected]);
  $this->email->to([email protected]);   
  $this->email->cc([email protected]); 
   $this->email->subject('sub');$this->email->message($messages);   
 $this->email->send();

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

0
votes

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();