我如何发送电子邮件在php与SMTP?



你好,请有人帮助我,为什么我有一个困难的时间,我无法识别错误,为什么它返回错误在设置flash数据,虽然电子邮件id匹配输出?我正在做一个忘记密码在我的登录页面使用PHP和代码编写框架

我需要安装SMTP来启用电子邮件方法还是我需要安装一些东西?

控制器:

public function index()
{
$this->load->model('model_users');
if($_SERVER['REQUEST_METHOD']=='POST')
{
$this->form_validation->set_rules('email','Email','required');
if($this->form_validation->run()==TRUE)
{
$email = $this->input->post('email');
$validationemail = $this->model_forgotpass->validationemail($email);
if($validationemail!=false)
{
$row = $validationemail;
$user_id = $this->session->userdata('id');
$user_data = $this->model_users->getUserData($user_id);
$string = time().$user_id.$email;
$hash_string = hash('sha256',$string);
$currentDate = date('Y-m-d H:i');
$hash_expiry = date('Y-m-d H:i',strtotime($currentDate. ' 1 days'));
$data = array(
'hash_key'=>$hash_string,
'hash_expiry'=>$hash_expiry,
);
$this->model_forgotpass->updatePasswordhash($data,$email);
$resetLink = base_url().'reset/password?hash='.$hash_string;
$message = '<p>Your reset password Link is here:</p>'.$resetLink;
$subject = "Password Reset link";
$sentstatus = $this->sendEmail($email,$subject,$message);
if($sentstatus==true)
{
$this->model_forgotpass->updatePasswordhash($data,$email);
$this->session->set_flashdata('success','Reset password link successfully sent');
redirect(base_url('forgotpass/index'));
}
else
{
$this->session->set_flashdata('error','Email sending error');
}
}
else
{
$this->session->set_flashdata('error','Invalid email id');
}
}
}
else
{
$this->load->view('forgotpass/index','refresh');
}

$this->load->view('forgotpass/index','refresh');

}
public function sendEmail($email,$subject,$message)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email',$config);
$this->email->set_newline("rn");
$this->email->from('noreply');
$this->email->to($email);
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
return true;
}
else
{
return false;
}
}

这是我的模型:

function validationemail($email)
{
if($email) {
$sql = 'SELECT * FROM users WHERE email = ?';
$query = $this->db->query($sql, array($email));
$result = $query->num_rows();
return ($result == 1) ? true : false;
}
return false;

}
function updatePasswordhash($data,$email)
{
$this->db->where('email',$email);
$this->db->update('users',$data);
}

我似乎无法识别这里的错误,它总是返回作为电子邮件发送错误,我仍然无法收到我的电子邮件中的消息,虽然我的用户名和密码是正确的,但为什么我不能处理它?

打印错误信息使用echo $this->email->print_debugger();在email else部分

相关内容

  • 没有找到相关文章

最新更新