2017-12-25 6 views
1

Gmailアカウントにメールが送信されないforgot_pass_identityがテーブルに設定されています。誰かが私が間違っていることを教えてもらえますか? 私は間違いを見つけられなかったコードをチェックします。パスワードを忘れた場合は、Gmailアカウントにメッセージが送信されない

if(isset($_POST['forgotSubmit'])){ 
//check whether email is empty 
    if(!empty($_POST['email'])){ 
    //check whether user exists in the database 
    $prevCon['where'] = array('email'=>$_POST['email']); 
    $prevCon['return_type'] = 'count'; 
    $prevUser = $user->getRows($prevCon); 
    if($prevUser > 0){ 
     //generat unique string 
     $uniqidStr = md5(uniqid(mt_rand()));; 

     //update data with forgot pass code 
     $conditions = array(
      'email' => $_POST['email'] 
     ); 
     $data = array(
      'forgot_pass_identity' => $uniqidStr 
     ); 
     $update = $user->update($data, $conditions); 

     if($update){ 
      $resetPassLink = 'http://example.com/resetPassword.php?fp_code='.$uniqidStr; 

      //get user details 
      $con['where'] = array('email'=>$_POST['email']); 
      $con['return_type'] = 'single'; 
      $userDetails = $user->getRows($con); 

      //send reset password email 
      $to = $userDetails['email']; 
      $subject = "Password Update Request"; 
      $mailContent = 'Dear '.$userDetails['first_name'].', 
      <br/>Recently a request was submitted to reset a password for your account. If this was a mistake, just ignore this email and nothing will happen. 
      <br/>To reset your password, visit the following link: <a href="'.$resetPassLink.'">'.$resetPassLink.'</a> 
      <br/><br/>Regards, 
      <br/>mysite'; 
      //set content-type header for sending HTML email 
      $headers .= "Content-type:text/html;charset=UTF-8" ; 
      //additional headers 
      //send email 
      mail($to,$subject,$mailContent,$headers); 

      $sessData['status']['type'] = 'success'; 
      $sessData['status']['msg'] = 'Please check your e-mail, we have sent a password reset link to your registered email.'; 
     }else{ 
      $sessData['status']['type'] = 'error'; 
      $sessData['status']['msg'] = 'Some problem occurred, please try again.'; 
     } 
    }else{ 
     $sessData['status']['type'] = 'error'; 
     $sessData['status']['msg'] = 'Given email is not associated with any account.'; 
    } 

}else{ 
    $sessData['status']['type'] = 'error'; 
    $sessData['status']['msg'] = 'Enter email to create a new password for your account.'; 
} 
//store reset password status into the session 
$_SESSION['sessData'] = $sessData; 
//redirect to the forgot pasword page 
header("Location:forgotPassword.php"); 
} 

この問題の解決方法を教えてください。ありがとうございます。

+0

メールを送信している可能性があります.Gmailがメールを受信して​​いる可能性がありますが、スパムとして破棄します。あなたのメールにはおそらくSPFレコードやDKIMはありません。次のURLを参照してください。https://support.google.com/mail/answer/6227174?hl=ja&ref_topic=6259779 –

答えて

1

最初に以下のヘッダを追加してみてください。

$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
$headers .= 'From: '.$from. "\r\n"; // Valid from address 

送信メールだけでなく、実際には他のパラメータにも依存します。

これが機能しない場合、以下のリンクを参照してください。

PHP mail function doesn't complete sending of e-mail

http://form.guide/email-form/php-script-not-sending-email.html

この情報がお役に立てば幸い!

+0

この回答を正しく入力していただきありがとうございます。お力になれて、嬉しいです。 –

関連する問題