Search code examples
phpcodeignitercodeigniter-3sendmail

Codeigniter 3 Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method


public function send_mail_verification(){
    $this->load->library('email');

    $config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'smtp.gmail.com',
        'smtp_port' => '587',
        'smtp_crypto' => 'tls',
        'smtp_user' => '[email protected]',
        'smtp_pass' => 'mypass',
        'charset'   => 'iso-8859-1'
    );

    $this->email->initialize($config);

    $this->email->from('[email protected]', 'Registration');
    $this->email->to('[email protected]');

    $this->email->subject('something');
    $this->email->message('Testing email.');

    if($this->email->send()){
        echo "success";
    }
    else{
        show_error($this->email->print_debugger());
    }
}

I've been looking at other solution that I find in the internet and none of them worked for me. I've also tried the mail function and changed some things in sendmail.ini and php.ini in xampp and that worked. However, the send mail configuration in codeigniter-3 is much better if I'm going to share my code to other so that they don't need to change some configuration in their sendmail.ini and php.ini. What do you think causes the error?


Solution

  • $this->email->set_newline("\r\n");
    

    I added this one and it worked... wonder why.