0

I am trying to send email in codeIgniter, I am receiving the email on example@mycompany.com but not able to receive them in gmail I tried this:

            $this->load->library('email');
            $config['useragent']        = 'CodeIgniter';
            $config['smtp_host']        = 'smtp.googlemail.com';
            $config['protocol']         = 'smtp';
            $config['smtp_user']        = 'example@gmail.com';
            $config['smtp_pass']        = '**********';
            $config['smtp_port']        = 465;
            $config['smtp_timeout']     = 30;  
            $config['wordwrap']         = TRUE;
            $this->email->initialize($config);
            $this->email->from('no-reply@mycompany.com', 'My company');
            $this->email->to($email);
            $this->email->subject('hello');
            $this->email->message($message);
            $this->email->set_mailtype('html');
            $this->email->send();
B. Desai
  • 16,414
  • 5
  • 26
  • 47
Usama Iftikhar
  • 183
  • 2
  • 14
  • Its not duplicate OP is using CodeIgniter. Which may have different issue @John Conde – B. Desai Apr 02 '18 at 12:15
  • Using a different library doesn't change anything unless they can show it specifically is a CodeIgniter issue. That doesn't seem to be the case here. The canonical question is commonly used for PHPMailer questions as well. – John Conde Apr 02 '18 at 12:16

2 Answers2

1

Try following configuration. Also you have to Less secure apps from your gmail account

$config = Array(    
              'protocol' => 'smtp',
              'smtp_host' => 'ssl://smtp.googlemail.com',
              'smtp_port' => 465,
              'smtp_user' => 'example@gmail.com',
              'smtp_pass' => '**********',
              'mailtype' => 'html',
              'charset' => 'iso-8859-1',
              'mailtype' => 'html',
              'wordwrap' => TRUE
        );

$this->load->library('email', $config); 
B. Desai
  • 16,414
  • 5
  • 26
  • 47
-1
Download the php mailer library in the following link:https://github.com/PHPMailer/PHPMailer/releases/tag/v5.2.26.
After download complete create phpmailer folder in library and extract the zip in php mailer folder...

<?php
require 'phpmailer/src/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "xxxxxxx@gmail.com";
$mail->Password = "xxxxxxxxx";
$mail->setFrom('from@example.com', 'First Last');
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'Add subject';
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
AngularJMK
  • 1,178
  • 13
  • 15