I can received the reset password mail, but it always show error code.
this is my app code
private void sendEmail(String email) { final String sendEmail = email; StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_FORGOT_PASSWORD, new Response.Listener<String>() { @Override public void onResponse(String response) { try { JSONObject jsonObject = new JSONObject(response); String success = jsonObject.getString("success"); if (success.equals("1")){ Toast.makeText(getApplication(),"Email successful send please check your email box.", Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_SHORT).show(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(getApplicationContext(),"Error" + error.toString(), Toast.LENGTH_SHORT).show(); } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> params = new HashMap<>(); params.put("email", email); return params; } }; RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(stringRequest); }
if the server response the success value equals is “1”
it should be show Email successful send please check your email box.
but it’s always show Errorcom.android.volley.ServerError. and the log error is
E/Volley: [3287] BasicNetwork.performRequest: Unexpected response code 500 for
when I check the link, it not get 500 error.
server code
require_once 'connect.php'; $email = $_POST['email']; $sql = "SELECT * FROM user WHERE UserEmail ='".$email."'"; $result = mysqli_query($conn,$sql); if(mysqli_num_rows($result)>0){ $row = mysqli_fetch_assoc($result); $eemail = $row['UserEmail']; $UserName = $row['UserName']; $title = "<div class='rcmBody'>Reset password instructions.<br><p>This letter was sent.</p><p>You received this email because this email address registered app, and the user requested to use the email passwrod reset function.</p><p>----------------------------------------------------------------------<br><strong><color=red>Important!</color></strong><br>----------------------------------------------------------------------</p><p>If you did not submit a password reset request or you are not a registered user of LUVTAS app. Please ignore and delete this email immediately. Only if you confirm that you need to reset your password, you need to continue reading the following.</p><p>----------------------------------------------------------------------<br><strong><color=red>Reset password instructions.</color></strong><br>----------------------------------------------------------------------</p>Please click the under link to verify your identity and access your account. (It's only good for 24 hours.)<br><a href='https://example.com' target='_blank' rel='noreferrer'>https://example.com</a><br><p>Regards;<br></p><p>Admin group.https://example.com</p></div>"; mail("$eemail","Reset your app password ",$title, "example@gmail.com"); $result['success'] = "1"; $result['message'] = "success"; echo json_encode($result ,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT); }
And if I use
mail("$eemail","Reset your luvtas app password ",$title, "example@gmail.com");
I cannot got email…..I don’t know why, But if I use
mail("$eemail","Reset your luvtas app password ","aaa", "example@gmail.com");
It’s fine. so what’s different?
Advertisement
Answer
the third parameter on mail function which is the message, each lines should not exceed 70 character,
You can use wordwrap to wrap the string to less than 70 character
and since $eemail
will be equal to $email
, the usage of $eemail
will be unnecessary
$email = $_POST['email']; $sql = "SELECT * FROM user WHERE UserEmail ='".$email."'"; $result = mysqli_query($conn,$sql); if(mysqli_num_rows($result)>0){ $row = mysqli_fetch_assoc($result); // Removed $eemail since UserEmail = $email $UserName = $row['UserName']; $title = "<div class='rcmBody'>Reset password instructions.<br><p>This letter was sent.</p><p>You received this email because this email address registered app, and the user requested to use the email passwrod reset function.</p><p>----------------------------------------------------------------------<br><strong><color=red>Important!</color></strong><br>----------------------------------------------------------------------</p><p>If you did not submit a password reset request or you are not a registered user of LUVTAS app. Please ignore and delete this email immediately. Only if you confirm that you need to reset your password, you need to continue reading the following.</p><p>----------------------------------------------------------------------<br><strong><color=red>Reset password instructions.</color></strong><br>----------------------------------------------------------------------</p>Please click the under link to verify your identity and access your account. (It's only good for 24 hours.)<br><a href='https://example.com' target='_blank' rel='noreferrer'>https://example.com</a><br><p>Regards;<br></p><p>Admin group.https://example.com</p></div>"; $title = wordwrap($title, 70); mail($email, "Reset your app password ", $title, "example@gmail.com"); $result['success'] = "1"; $result['message'] = "success"; echo json_encode($result ,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT); }