Advertisement
Guest User

Untitled

a guest
Jul 26th, 2018
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2.  
  3. $uniqueid = "";
  4. $username = "";
  5.  
  6. use PHPMailer\PHPMailer\PHPMailer;
  7. use PHPMailer\PHPMailer\Exception as PHPMailerException;
  8. require dirname(__FILE__) . '/phpmailer/src/Exception.php';
  9. require dirname(__FILE__) . '/phpmailer/src/PHPMailer.php';
  10. require dirname(__FILE__) . '/phpmailer/src/SMTP.php';
  11.  
  12. $db = mysqli_connect('localhost', 'root', '', 'occupation');
  13.  
  14. if (!$db) {
  15. die("Connection failed: " . mysqli_connect_error());
  16. }
  17.  
  18. $email=$_GET['email'];
  19. //***********here query in the data base but not valid if it exists********************
  20. $sql ="SELECT uniqueid, username FROM users WHERE email='$email'";
  21.  
  22. if (isset($_GET['email'])) {
  23.  
  24. $message = "Salut! Bienvenue au site. \nvotre ID est : '$uniqueid'\n"
  25. . "votre nom d'utilisateur est : '$username'";
  26.  
  27. $subject = 'Merci';
  28.  
  29. // ========== SEND EMAIL TO USER ======================
  30. $mail = new PHPMailer(true);
  31. $smtp_credentials = [
  32. 'username' => 'email@gmail.com', // change to your gmail address
  33. 'password' => 'password' // change to your gmail password
  34. ];
  35. try {
  36. $mail->isSMTP();
  37. $mail->isHTML(true);
  38. $mail->SMTPDebug = 0;
  39. $mail->SMTPAuth = true;
  40. $mail->Username = $smtp_credentials['username'];
  41. $mail->Password = $smtp_credentials['password'];
  42. $mail->SMTPSecure = 'tls';
  43. $mail->Host = 'smtp.gmail.com';
  44. $mail->Port = 587;
  45. $mail->SMTPOptions = array(
  46. 'ssl' => array(
  47. 'verify_peer' => false,
  48. 'verify_peer_name' => false,
  49. 'allow_self_signed' => true
  50. )
  51. );
  52. // email context
  53. $mail->setFrom($smtp_credentials['username'], 'Mohamed Douhaji');
  54. //*********************here you will leave in username because you have not received data from database**************************
  55. $mail->addAddress($email, $username);
  56. $mail->Subject = $subject;
  57. $mail->Body = $message;
  58. $mail->AltBody = strip_tags($message);
  59.  
  60. // send email
  61. $mail->send();
  62. } catch (PHPMailerException $e) {
  63. die('Message could not be sent. ' . $mail->ErrorInfo);
  64. }
  65.  
  66. }
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement