使用codeigniter通过电子邮件验证注册

时间:2015-09-30 06:40:49

标签: php codeigniter codeigniter-3

我尝试做项目验证电子邮件,但有障碍。当我提交数据寄存器错误。请给我编码解释,出了什么问题...... ......请他的解释

控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Register extends CI_Controller {

    public function __construct(){
        parent::__construct();
        $this->load->model('M_register');
    } 

    public function index() {
        $this->load->helper('form');
        $data = array ( 'isi' => 'login/vregister');
        $this->load->view('layout/wrapper',$data);
    }

    function submit() {

        //passing post data dari view
        $_POST['dob'] = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];

        $firstname = $this->input->post('firstname');
        $lastname = $this->input->post('lastname');     
        $password = $this->input->post('password');
        $email = $this->input->post('email');
        $dob = $this->input->post('dob');
        $jkl = $this->input->post('jkl');   
        $lastlogin = $this->input->post('lastlogin');       

        //memasukan ke array
        $data = array(
            'firstname' => $firstname,
            'lastname' => $lastname,
            'password' => $password,
            'email' => $email,  
            'dob' => $dob,
            'jkl' => $jkl,
            'lastlogin' => $lastlogin,
            'active' => 0
        );
        //tambahkan akun ke database
        $this->m_register->add_account($data);
        //redirect(base_url().'homepage/homepage'); 
        $id = $this->m_register->add_account($data);

        //enkripsi id
        $encrypted_id = md5($id);

        $this->load->library('email');
        $config = array();
        $config['charset'] = 'utf-8';
        $config['useragent'] = 'Codeigniter';
        $config['protocol']= "smtp";
        $config['mailtype']= "html";
        $config['smtp_host']= "ssl://smtp.gmail.com";//pengaturan smtp
        $config['smtp_port']= "465";
        $config['smtp_timeout']= "400";
        $config['smtp_user']= "duwi@gmail.com"; // isi dengan email kamu
        $config['smtp_pass']= "*******"; // isi dengan password kamu
        $config['crlf']="\r\n"; 
        $config['newline']="\r\n"; 
        $config['wordwrap'] = TRUE;
        //memanggil library email dan set konfigurasi untuk pengiriman email

        $this->email->initialize($config);
        //konfigurasi pengiriman
        $this->email->from($config['smtp_user']);
        $this->email->to($email);
        $this->email->subject("Verifikasi Akun");
        $this->email->message(
            "terimakasih telah melakuan registrasi, untuk memverifikasi silahkan klik tautan dibawah ini<br><br>"
        );

        if($this->email->send())
        {
            echo "Berhasil melakukan registrasi, silahkan cek email kamu";
        }else
        {
            echo "Berhasil melakukan registrasi, namu gagal mengirim verifikasi email";
        }

        echo "<br><br><a href='".site_url("index.php/login/login")."'>Kembali ke Menu Login</a>";
    }   

}

1 个答案:

答案 0 :(得分:1)

我使用以下配置在我的网站上发送电子邮件:

            $this->load->library('email');
            $config['protocol'] = 'sendmail';
            $config['mailpath'] = '/usr/sbin/sendmail';
            $config['charset'] = 'utf-8';
            $config['mailtype'] = "html";

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

或许尝试将“协议”更改为sendmail?