dsm13698679318 2016-11-15 21:36
浏览 46
已采纳

如果电子邮件存在则出错 - codeigniter php

I am having following problem when i run forgot page the email check if working fine, but if the email is exists the mail sent section get following error not email was sent.

enter image description here

User.php (controller)

public function forgot() {

// create the data object
$data = new stdClass();

// load form helper and validation library
$this->load->helper('form');
$this->load->library('form_validation');

$this->form_validation->set_rules('email', 'Email', 'required|valid_email'); 

if($this->form_validation->run() == FALSE) {
    // Load this page with error
    $this->load->view('header');
    $this->load->view('user/forgot/forgot');
    $this->load->view('footer');
}else{
    $email = trim($this->input->post('email'));  
    //$clean = $this->security->xss_clean($email);
    $userInfo = $this->user_model->checkUserEmail($email);

    if($userInfo) {
        $this->password_to_email($email, $userInfo);
        $this->load->view('header');
        $this->load->view('user/forgot/password_sent', array('email' => $email));
        $this->load->view('footer');
    } else {
        $data->error = 'We cant find your email address.';

        $this->load->view('header');
        $this->load->view('user/forgot/forgot', $data);
        $this->load->view('footer');
    }

}

}

private function password_to_email($email, $firstname) { $this->load->library('email');

$from_email = "test@test.com";

$token = md5($this->config->item('salt') . $firstname);

$this->email->set_mailtype('html');
$this->email->from($from_email);
$this->email->to($email);
$this->email->message('Reset your Password');

$message = '<html><body>';
$message .= '<p>Hello '.$firstname.'</p>';
$message .= '<p>Please use following link to reset your password.<br><a href="'.base_url().'reset/reset/'.$email.'/'.$token.'"></a></p>';
$message .= '<p>Thank you!</p>';
$message .= '</body></html>';

$this->email->message($message);
$this->email->send();

}

  • 写回答

1条回答 默认 最新

  • duanniwu7730 2016-11-15 22:04
    关注

    Well you've not shown your model for $this->password_to_email($email, $userInfo); so I just have to guess a little here.

    The Clue is in the Error

    Message:Object of class stdClass could not be converted to string.

    But what will be happening is that $firstname in

    $token = md5($this->config->item('salt') . $firstname);
    

    needs to be a string and you are passing in an object from your DB query.

    So your call to

    $this->password_to_email($email, $userInfo);
    

    would need to be something like

    $this->password_to_email($email, $userInfo->firstname);
    

    So you need to ensure you are passing in a string.

    Performing var_dump($userInfo);in say...

    ...
    }else{
        $email = trim($this->input->post('email'));  
        //$clean = $this->security->xss_clean($email);
        $userInfo = $this->user_model->checkUserEmail($email)
        var_dump($userInfo);
    ...
    

    Will show you the format of what $userInfo actually is. Then you can go from there. You just need to ensure you are getting $firstname as a string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口