How to send verfication Email from an Android Application using 000webhost

32 Views Asked by At

I am developing a Chat Application where a user need to verify his email before he can enter his other information while signing up. I know about Firebase Email Verification but I don't want to use link verification, instead I'm trying to use OTP verification. So I need to send an OTP to user's mail. I did that using 000Webhost and a PHP code, thanks to the help of an Youtube video. It was working very well a few days ago but now for some reason the website isn't sending any email. The email quota isn't full, not even one email has been sent from this website. The PHP code I used in that website-

<?php if(isset($_POST["email"]) && isset($_POST["code"])){ $to=$_POST["email"];
$subject="One Time Password (OTP) Confirmation - Chatty";
$message="Dear User, \nPlease use the following OTP- " . $_POST["code"] . " to verify your Email Account and start chit chatting using Chatty.
    \n\nDo not reply, this email is automatically generated by Chatty. ";
    if(mail($to,$subject,$message)) echo "Sent";
    else echo "failed";} ?>

and the code I'm using inside my Application is shown below-

private void sendOTP(){
    Random r = new Random();
    code = r.nextInt(899999)+100000; //can't be more than 999999
    String url = "https://joyandroidsendemail.000webhostapp.com/sendingEmailtoUser.php"; //php code for sending random OTP
    RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());

    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
            response -> Toast.makeText(OTPActivity.this, response, Toast.LENGTH_SHORT).show(),
            error -> Toast.makeText(OTPActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show()){
        @Nullable
        @Override
        protected Map<String, String> getParams() throws AuthFailureError { 
            Map<String, String> params = new HashMap<>();
            params.put("email", getIntent().getStringExtra("email"));
            params.put("code",String.valueOf(code));
            return params;
        }
    };
    requestQueue.add(stringRequest);
}

The echo from PHP code which says OTP sent successfully is showing to the app as a Toast, that means the link is working right? Then why is no mail coming to the given email? What could be the problem here? It was working awhile ago, I don't know why it isn't working anymore. Is it a website problem? Is there any other way do this? I even echoed the Email and the code to see if the parameters are passing at all, and yes the response was that email and the code. That means the email and the code is passing successfully. Then what is the problem? Is it the PHP code?

0

There are 0 best solutions below