How can I get fix this error of this email issue with codeigniter?

I have a problem like this.I want to send a mail from my web application so I put this in my controller.

$from_email = "tharuwan40@gmail.com";
$to_email = "warimali94@gmail.com";

//Load email library
$this->load->library('email');
$this->email->from($from_email, 'Info');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();

This web application is still running on localhost.I tried so many examples in the net and which have been posted in stack overflow tooo.But there was nothing on my mail.Email was not send.How can I get fix this?

1 answer

  • answered 2018-02-13 03:36 Param Bhat

    Create config array

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

    then

      $this->load->library('email', $config);
    
      $this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
      $this->email->to('target@gmail.com'); //receiver mail
    
      $this->email->subject('testing');
      $this->email->message($message);
    
      if($this->email->send()) //sending mail
      {
         echo 'Mail sent';
      }
      else
      { 
         print_r($this->email->print_debugger(), true);
      }
    

    Configuration in sendmail.ini

    path [xampp folder]\sendmail\sendmail.ini

    Configurations

    [sendmail]
    
    smtp_server=smtp.gmail.com
    smtp_port=25
    error_logfile=error.log
    debug_logfile=debug.log
    auth_username=myemail@gmail.com
    auth_password=yourgmailpassword
    force_sender=myemail@gmail.com
    

    open php.ini config file and search for[mail function]

    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
    

    Restart Server

    Main Source