-3

Not Sending Email in web service using php.

The code is below please check and suggest the kind changes.

 <?php

   $con=mysqli_connect("localhost","root","","database");

   if(isset($_POST) & !empty($_POST)){

      $email = mysqli_real_escape_string($con, $_POST['email']);
      $mail=$_POST['mail'];
      $sql = "SELECT * FROM user WHERE email = '$email'";
      $res = mysqli_query($con, $sql);
      $count = mysqli_num_rows($res);
      if($count == 1){
            $r = mysqli_fetch_assoc($res);
            $password = $r['password'];
            $to = $r['email'];
            $subject = "Your Recovered Password";
            $message = "Please use this password to login " .$password ;
            $headers = "From : vivek@codingcyber.com";
            $m=mail($to, $subject, $message, $headers, "-f ".$email);       
            if($m){
                echo "Your Password has been sent to your email id";
            }
            else{
                echo "Failed to Recover your password, try again";
            }

      }
    else{
            echo "User name does not exist in database";
    }
   }
 mysqli_close($con);

?>
RedBassett
  • 3,469
  • 3
  • 32
  • 56
Hasid Mansoori
  • 171
  • 1
  • 1
  • 10

1 Answers1

0
//php mail syntax 
mail(to,subject,message,headers,parameters);

checkout this link mail() function

Rushil K. Pachchigar
  • 1,263
  • 2
  • 21
  • 40