简体   繁体   中英

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' => 'myacc@gmail.com',
        'smtp_pass' => 'mypass',
        'charset'   => 'iso-8859-1'
    );

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

    $this->email->from('myemail3@gmail.com', 'Registration');
    $this->email->to('tosomeonemail@gmail.com');

    $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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM