简体   繁体   中英

codeigniter unable to send email

PHP code:

    $from  = 'shahrushabh1996@gmail.com';
    $config = array(
            'protocol'=>'smtp',
            'smtp_host'=>'ssl://smtp.googlemail.com',
            'smtp_port'=>'465',
            'smtp_user'=>'shahrushabh1996@gmail.com',
            'smtp_pass'=>'********',
            'mailtype'=>'html',
            'charset'=>'UTF-8'
        );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->to($personemail);
    $this->email->from($from);
    $this->email->subject('it is a demo email by Rushabh Shah');
    $this->email->message('demo message');
    if(!$this->email->send()){
        show_error($this->email->print_debugger());
    }
    else{
        echo 'email is sent';
    }

Error:

Unable to send email using PHP mail().

Please help me how to resolve following error? this method is working fine in different controller but not working in this controller how to resolve it? please help me.

Try this

$config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => '465',
        'smtp_user' => 'xxxx@gmail.com',
        'smtp_pass' => 'xxxxx',
        'mailtype'  => 'html',
        'starttls'  => true,
        'newline'   => "\r\n"
    );

    $this->load->library('email', $config);

    $this->email->from('someuser@gmail.com', 'Test');
    $this->email->to('test@test.com');
    $this->email->subject('Test Email');
    $this->email->message('Hello World');

    $this->email->send();

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