简体   繁体   中英

Send Email from Codeigniter Resulted Blank Page

I want to send an email from Codeigniter, my code is like this

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

    $message = 'test message';
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->from('myemail@gmail.com');
    $this->email->to('somebody@gmail.com');
    $this->email->subject('Test Message');
    $this->email->message($message);
    if($this->email->send()){
        echo 'Email sent.';
    }
    else
    {
        show_error($this->email->print_debugger());
    }
}

i have edited php.ini and enabled opensll. But when i try to send an email,my code resulted blank page, no success message or error message appear. i have no clue what should i do, Any clue ?

$config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_user' => 'temp@gmail.com',
        'smtp_pass' => 'password',
        'mailtype' => 'html',
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");

Many be error with smtp host try this

use:

$this->email->send()
$this->email->print_debugger()

instead of:

if($this->email->send()){
    echo 'Email sent.';
}
else
{
    show_error($this->email->print_debugger());
}

to debug

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