我在codeigniter中创建了一个注册页面,一切都很好,但是当我点击注册时,它会将所有数据插入到数据库中,但它不会向邮件发送确认信并给出错误:
以下SMTP错误已经发生:99无法分配请求 ADDRESS无法使用PHP SMTP发送电子邮件。你的服务器可能不是 配置使用此方法发送邮件。
日期:FRI,2017年6月23日 16:15:55 +0300 FROM:“WTF”返回路径: TO:LUT_MILCEY@MAIL.RU主题: =?UTF-8?Q?VERIFY = 20YOUR = 20EMAIL = 20AD?==?UTF-8?Q?DRESS?= REPLY-TO:USER-AGENT:CODEIGNITER X-SENDER: LUT.MILCEY@GMAIL.COM X-MAILER:CODEIGNITER X-PRIORITY:3(NORMAL) 消息ID:< 594D148BCAB8E@GMAIL.COM> MIME-VERSION:1.0
这是我的控制器:
<?php
class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url', 'security'));
$this->load->library(array('session', 'form_validation', 'email'));
$this->load->database();
$this->load->model('User_model');
}
function index()
{
$this->register();
}
function register()
{
//set validation rules
$this->form_validation->set_rules('username', 'Username', 'trim|required|alpha|min_length[3]|max_length[30]|is_unique[instructors.instructors_slug]xss_clean');
$this->form_validation->set_rules('mail', 'Email', 'trim|required|valid_email|is_unique[instructors.mail]');
$this->form_validation->set_rules('password', 'password', 'trim|required|md5');
$this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|md5|matches[password]');
$to_email= $this->input->post('mail');
$data['courses'] = $this->Popular_courses_model->get_popular_courses();
$data['news'] = $this->News_model->get_news();
//validate form input
if ($this->form_validation->run() == FALSE)
{
// fails
$this->load->view('templates/header');
$this->load->view('pages/index', $data);
$this->load->view('templates/footer');
}
else
{
//insert the user registration details into database
$data = array(
'instructors_slug' => $this->input->post('username'),
'mail' => $to_email,
'password' => $this->input->post('password')
);
// insert form data into database
if ($this->User_model->insertUser($data)) {
if ($this->User_model->sendEmail($to_email)) {
// successfully sent mail
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>');
redirect('user/register');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">'.$to_email.' gondermir '.$this->email->print_debugger().'</div>');
redirect('user/register');
}
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">daxil elemir</div>');
redirect('user/register');
}
}
}
function verify($hash=NULL)
{
if ($this->User_model->verifyEmailID($hash))
{
$this->session->set_flashdata('verify_msg','<div class="alert alert-success text-center">Your Email Address is successfully verified! Please login to access your account!</div>');
redirect('user/register');
}
else
{
$this->session->set_flashdata('verify_msg','<div class="alert alert-danger text-center">Sorry! There is error verifying your Email Address!</div>');
redirect('user/register');
}
}
}
?>
这是我的模特:
<?php
class User_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//insert into user table
function insertUser($data)
{
return $this->db->insert('instructors', $data);
}
//send verification email to user's email id
function sendEmail($to_email)
{
$from_email = 'lut.milcey@gmail.com'; //change this to yours
$subject = 'Verify Your Email Address';
$message = 'Dear User,<br /><br />Please click on the below activation link to verify your email address.<br /><br /> http://www.wtf.az/user/verify/' . md5($to_email) . '<br /><br /><br />Thanks<br />Mydomain Team';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'lut.milcey@gmail.com'; //change this
$config['smtp_pass'] = 'mypass'; //change this
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$this->email->initialize($config);
//send mail
$this->load->library('email');
$this->email->from($from_email, 'WTF');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
return $this->email->send();
}
//activate user account
function verifyEmailID($key)
{
$data = array('status' => 1);
$this->db->where('md5(mail)', $key);
return $this->db->update('instructors', $data);
}
}
?>
答案 0 :(得分:0)