Php Codeigniter电子邮件-浏览器持续加载

Php Codeigniter电子邮件-浏览器持续加载,php,codeigniter,Php,Codeigniter,我正在尝试使用codeigniter发送电子邮件 <?php class email_page extends CI_Controller{ function __construct(){ parent::__construct(); } function index(){ $config = Array( 'protocol'=>'smtp', 'smtp_ho

我正在尝试使用codeigniter发送电子邮件

<?php
class email_page extends CI_Controller{
    function __construct(){
        parent::__construct();
    }

    function index(){
        $config = Array(
                'protocol'=>'smtp',
                'smtp_host' => 'ssl://smtp.googlemail.com',
                'smtp_port' => '465',
                'smtp_user' => 'testmail@gmail.com',
                'smtp_pass' => 'password'
            );

        $this->load->library('email', $config);
        $this->email->set_newline('\r\n');

        $this->email->from('testmail@gmail.com','Sender name');
        $this->email->to('testmail@gmail.com');
        $this->email->subject('Test mail');
        $this->email->message('This is a test mail from codeigniter');

        if($this->email->send()){
            echo "Your mail was sent successfully!!!";
        }
        else{
            show_error($this->email->print_debugger());
        }
    }
}

我发现了错误,只需将端口更改为25即可

function test(){
    $config = Array(
            'protocol'=>'smtp',
            'smtp_host' => 'smtp.gmail.com',
            'smtp_port' => '25',
            'SMTPAuth' => true,
            'smtp_user' => 'email@gmail.com',
            'smtp_pass' => 'password'
        );

    $this->load->library('email', $config);
    //$this->email->set_newline('\r\n');

    $this->email->from('email@gmail.com','Sender name');

    $this->email->to('email@micromerger.com');
    $this->email->subject('Test mail');
    $this->email->message('This is a test mail from codeigniter');
   //print_r($this->email);exit;
    if( ! $this->email->send()){
    //print_r("234");exit;
        echo "Your mail was sent successfully!!!";
    }
    else{
    //print_r("345");exit;
        show_error($this->email->print_debugger());
    }
}

在此处更改您的帐户设置

https://www.google.com/settings/security/lesssecureapps

我自己找到了答案

 $this->email->set_newline('\r\n');
将上面的行更改为

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

我不确定这是怎么发生的。

您的SMTP凭据正确吗?你有任何错误日志吗?我没有使用gmail,而是在一段时间后出现了这个错误。致命错误:在1870行的C:\xampp\htdocs\Codeigniter\system\libraries\Email.php中超过了300秒的最长执行时间。这些行之间有什么区别?