【问题标题】:How to send email from localhost using CodeIgniter with Gmail如何使用 CodeIgniter 和 Gmail 从本地主机发送电子邮件
【发布时间】:2018-05-20 03:45:05
【问题描述】:

大家好,我目前正在开发一个 CodeIgniter 应用程序,用户可以在其中创建自己的帐户等。

我正在尝试创建一个功能来恢复密码,以防丢失或忘记。 这是我的代码:

    public function admin_recover(){

        $this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[7]|valid_email');

        if($this->form_validation->run() == FALSE){
        //Load View Into Template

        $this->template->load('admin', 'login', 'users/recover');

    } else {
        //Get Post Data
        $email = $this->input->post('email');
        $password = $this->input->post('password');

        $user_email = $this->User_model->get_list();

        if($user_email){
            $user_email_data = array(
                'email' => true
            );
        ///////// Sending email
        // Configure email library

        $config['wordwrap'] = FALSE;
        $config['mailtype'] = 'html';
        $config['crlf'] = '\r\n';
        $config['charset']='utf-8';
        $config['newline']="\r\n";
        $config['priority']=1;
        $config['protocol']='smtp';
        $config['smtp_host']='ssl://smtp.gmail.com';
        $config['smtp_port']='25';
        $config['smtp_timeout']='30';
        $config['smtp_user']='kuaf1998@gmail.com';
        $config['smtp_pass']='mypassword';
        $config['newline']="\r\n";


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

        $this->email->from('no-reply@socialgeek.com', 'Social Geek');
        $this->email->to('kebin1421@hotmail.com');       
        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');
        $this->email->send();


        if($this->email->send()) 
        $this->session->set_flashdata("success","Email sent successfully."); 
        else 
        $this->session->set_flashdata("error","Error in sending Email.");

        echo $this->email->print_debugger();
        //////////////      
        }   
    }
}

我正在使用 gmail smtp 服务从本地主机发送电子邮件,但我仍然无法实现。知道如何解决这个问题吗?

我已经对我的 xampp>php>php.ini 上的 ini 文件进行了一些更改(我正在使用 xampp)

当我转到视图时,我收到此错误:

感谢您的帮助。

【问题讨论】:

标签: php smtp localhost codeigniter-3


【解决方案1】:

尝试使用下面的这些配置设置,让我知道它是否适合您。

$config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com',
    'smtp_port' => 465,
    'smtp_user' => 'user@gmail.com',
    'smtp_pass' => 'yourpassword',
    'mailtype' => 'html',
    'charset' => 'iso-8859-1'
);

【讨论】:

  • 您确定您的服务器配置中没有禁用 mail() 功能吗?
  • 什么意思?据我所知,我所要做的就是“取消注释”ini文件上的扩展名,对吗? "extension=php_smtp.dll"
猜你喜欢
  • 2015-05-29
  • 2015-08-22
  • 1970-01-01
  • 1970-01-01
  • 2016-11-02
  • 2012-05-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多