Can't send mail on 000webhost with php

0

I have made a small php project on 000webhost. The system sends mail to the user if he/she forgets password to reset it. But the problem is that it can't send mail at all. Here is my php code:

<?php
$tomail=$_POST["usermail"];
$subject="Password Reset";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$tomail."\r\n";
$link="https://dhankosh-in.000webhostapp.com/reset_password.php";
$message="<html><head></head><body><p>Click on the link below to reset your password</p><br><br><a href='".$link."'>Click here to reset your password</a></body></html>";
if(mail($tomail,$subject,$message,$headers))
{
    $myobj=array('status'=>'success','message'=>'Check your mail to reset password!!');
    echo json_encode($myobj);
}
else{
    $myobj=array('status'=>'error','message'=>'Invalid e-mail!!');
    echo json_encode($myobj);
}
?>

It sends the response as 'Check your mail to reset password!!' but I don't receive any mail. Trying it for so many hours but with no success!! Please help!!

Vipul Tyagi

Posted 2019-07-31T04:38:51.653

Reputation: 1

Can you check mail server log files? – AnFi – 2019-07-31T04:43:54.350

Perhaps 000webhost don't provide one!! – Vipul Tyagi – 2019-07-31T04:44:49.870

Answers

0

I tried you code and it worked. (I edited the first line to be a fixed email address)

Turn on sendmail in the control panel (if it's off)

  • Website settings
    • General
      • Sendmail

Be aware that the free account is limited to 50 emails per day.

Jasen

Posted 2019-07-31T04:38:51.653

Reputation: 499

When I tried it for first time, it actually sent mail for once. But now it is not working!! – Vipul Tyagi – 2019-07-31T07:00:31.233

sometimes free services are worth less than what you paid, regrettably that may include this answer also. – Jasen – 2019-07-31T09:21:40.067

Yes, it sends mail after 2-3 hours! – Vipul Tyagi – 2019-07-31T13:55:49.830