Advertisement
adminkacang

SendOTP.php

Jul 27th, 2022 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "";
  4. $password = "";
  5. $database  = "";
  6.  
  7. //Variables submitted by the users
  8. $userToPost = $_POST["userToPost"];
  9.  
  10.  
  11. // Create connection
  12. $conn = new mysqli($servername, $username, $password, $database);
  13. // Check connection
  14. if ($conn->connect_error) {
  15.   die("Connection failed: " . $conn->connect_error);
  16. }
  17.  
  18. $sql = "SELECT email FROM users WHERE username = '" . $userToPost . "'";
  19. $result = $conn->query($sql);
  20.  
  21. if ($result->num_rows > 0) {
  22.   // output data of each row
  23.   while($row = $result->fetch_assoc()) {
  24.     $userEmail = $row["email"];
  25.   }
  26. }
  27.  
  28. $sql = "SELECT otp FROM users WHERE username = '" . $userToPost . "'";
  29. $result = $conn->query($sql);
  30.  
  31. if ($result->num_rows > 0) {
  32.   // output data of each row
  33.   while($row = $result->fetch_assoc()) {
  34.     $userVerificationOtp = $row["otp"];
  35.   }
  36. }
  37.  
  38. $hashedOTP = password_hash($userVerificationOtp, PASSWORD_DEFAULT);
  39.  
  40. ini_set( 'display errors', 1);
  41. error_reporting(E_ALL);
  42.  
  43. $to = $userEmail;
  44.  
  45. $subject = "OTP - Verification ( TOUR PUO V2 )";
  46. $message = '
  47.    
  48. GEMENTAR TOUR PUO V2 EMAIL VERIFICATION
  49. Click link below to verify
  50.  
  51. HIDDEN =' . $userEmail . '&otp=' . $hashedOTP . '
  52. ';
  53. $headers = "From:" . $from;
  54.  
  55. mail($to,$subject,$message,$headers);
  56.  
  57.  
  58. echo "The Email Message was successfully sent.";
  59.  
  60.  
  61.  
  62. $conn->close();
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement