我可以收到重置密码的邮件,但它总是显示错误代码

I can received the reset password mail, but it always show error 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);
    }

如果服务器响应成功值为“1”

应该显示Email successful send please check your email box.

但它始终显示 Errorcom.android.volley.ServerError。并且日志错误是

E/Volley: [3287] BasicNetwork.performRequest: Unexpected response code 500 for

当我检查 link 时,它没有收到 500 错误。

服务器代码

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

如果我使用

mail("$eemail","Reset your luvtas app password ",$title, "example@gmail.com");

我收不到电子邮件.....我不知道为什么,但是如果我使用

mail("$eemail","Reset your luvtas app password ","aaa", "example@gmail.com");

没关系。那有什么不同呢?

mail函数的第三个参数是消息,每行不超过70个字符,

您可以使用 wordwrap 将字符串换行到小于 70 个字符

并且由于 $eemail 将等于 $email,因此不需要使用 $eemail

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