2016-11-15 5 views
-2

私は次の問題を抱えています。電子メールが正常に機能していれば、電子メールチェックを忘れてしまいます。誰も助けてください電子メールが出ている場合エラー - codeignitor php

enter image description here

User.php(コントローラ)

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'); 
    } 

} 

}

プライベート関数password_to_email($ eメールは、$ FIRSTNAME){ $ this-> load-> libraryメソッド('Eメール');

$from_email = "[email protected]"; 

$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(); 

}

答えて

2

さてあなたは、ます$ this-> password_to_email($メール、$のUserInfo)のためのモデルを示していませんでした。だから私はここでちょっと考えなければならない。

手がかりがエラーである

メッセージ:クラスはstdClassのオブジェクトを文字列に変換することができませんでした。

しかし、何が起こっされること

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

でその$のFIRSTNAMEが文字列や、あなたのDBクエリからオブジェクトに渡しているである必要があります。

ので

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

へのお電話は、あなたは、あなたが文字列で渡していることを確認する必要があり

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

ようなものにする必要があります。

実行のvar_dump($のUserInfo);と言う中...

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

はあなたに$のUserInfoが実際に何であるかのフォーマットが表示されます。それから、そこから行くことができます。 $ firstnameを文字列として確実に取得する必要があります。

+0

私は次の 'object(stdClass)#23(12){[" id "] =>文字列(1)" 4 "[" firstname "] => string(8)" Rahamath " = "string"(26) "[email protected]" ["password"] = "文字列(2) > "string"(19) "2016年11月13日22:24" "" $ 2y $ 10 $ EhhXwbTLCSVpK4kE42f1neYFNkMn6GlWkTMjGY/ZL1ySbi5xdruiG "[" avatar "] =>文字列(11)" default.jpg "[" created_at "] => (1) "0" ["is_deleted"] =>文字列(1) "0"} ' –

+0

変更後は正常に動作します。ありがとうございます $ this-> password_to_email($ email、$ userInfo-> firstname); –

+0

素敵:)あなたは大歓迎です!私はテストコードでここをチェックしていただけです。 – TimBrownlaw

関連する問題