0

I have used the code bellow in order to send email, but does not work in local and live server?

//this function sends a confirmation email to the user while registration
public function send_email($email,$message,$subject) {
     // configuration
    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'example@gmail.com', 
      'smtp_pass' => 'password', 
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->from('example@gmail.com');
    $this->email->to($email);
    $this->email->subject($subject);
    $this->email->message($message);
    $result = $this->email->send();
    $this->email->clear();
    return ($result);
}

2 Answers2

1

You are using gmail smtp right? I am facing same problem like this before. then i activate Allow less secure apps on my google account

enter image description here

and then it work

0

Try these settings:

// The mail sending protocol.
$config['protocol'] = 'smtp';
// SMTP Server Address for Gmail.
$config['smtp_host'] = ssl://smtp.googlemail.com
// SMTP Port - the port that you is required
$config['smtp_port'] = 465;
// SMTP Username like. (abc@gmail.com)
$config['smtp_user'] = $sender_email;
// SMTP Password like (abc***##)
$config['smtp_pass'] = $user_password;
// Load email library and passing configured values to email library
$this->load->library('email', $config);
// Sender email address
$this->email->from($sender_email, $username);
// Receiver email address.for single email
$this->email->to($receiver_email);
//send multiple email
$this->email->to(abc@gmail.com,xyz@gmail.com,jkl@gmail.com);
// Subject of email
$this->email->subject($subject);
// Message in email
$this->email->message($message);
// It returns boolean TRUE or FALSE based on success or failure
$this->email->send(); 
Aman Agarwal
  • 132
  • 7