Advertisement
Guest User

Untitled

a guest
May 20th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. <?php
  2. include_once "connect.php";
  3. include "crypt.php";
  4. require 'mailer/PHPMailerAutoload.php';
  5.  
  6. if (mysqli_connect_errno($con))
  7. {
  8. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  9. }
  10.  
  11. $userid = $_POST['userkey'];
  12. //$userid = 'vthakkar1994@gmail.com';
  13. $result = mysqli_query($con,"SELECT * FROM hope_users where user_email='$userid'");
  14. $row = mysqli_fetch_array($result);
  15. $count = mysqli_num_rows($result);
  16. $usernme = $row[2]." ".$row[3];
  17. $passkey = randomPassword();
  18. $data = $usernme." ".$passkey;
  19.  
  20. function randomPassword() {
  21. $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
  22. $pass = array(); //remember to declare $pass as an array
  23. $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  24. for ($i = 0; $i < 8; $i++) {
  25. $n = rand(0, $alphaLength);
  26. $pass[] = $alphabet[$n];
  27. }
  28. return implode($pass); //turn the array into a string
  29. }
  30. if ($count > 0){
  31.  
  32. }
  33. if ($userid)
  34.  
  35. {
  36. $mail = new PHPMailer;
  37. $mail->isSMTP(); // Set mailer to use SMTP
  38. $mail->Host = 'smtp.gmail.com'; // Specify main and backup server
  39. $mail->SMTPAuth = true; // Enable SMTP authentication
  40. $mail->Username = 'hope.dyslexiaapp@gmail.com'; // SMTP username
  41. $mail->Password = 'hopemyapp'; // SMTP password done
  42. $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  43. $mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
  44. $mail->setFrom('hope.dyslexiaapp@gmail.com', 'Dyslexia App'); //Set who the message is to be sent from
  45. $mail->addReplyTo('hope.dyslexiaapp@gmail.com', 'Dyslexia App'); //Set an alternative reply-to address
  46. $mail->addAddress($userid); // Name is optional
  47. $mail->WordWrap = 50; // Set word wrap to 50 characters
  48. $mail->isHTML(true); // Set email format to HTML
  49.  
  50. $mail->Subject = '"Hope" - Password Recovery System';
  51. $mail->Body = '<div style="border:solid thin #903; width:600px; height: 200px;margin:30px; background-color:#FCF;">
  52. <div style="text-align:center;width: 15%; float:left;" >
  53. <img src="http://oi58.tinypic.com/5wdw0x.jpg" style="max-width:50px; margin:20px;"/>
  54. </div>
  55. <div style="text-align:center; width:80%; float:left;">
  56. <div style="text-align:left;">
  57. <h2>Hope - Password Recovery System</h2>
  58. </div>
  59. <div style="text-align:left;font-size:12px;">
  60. Hello <b>'.$usernme.',</b> <br />
  61. You have requested to get your password reset for <br /><b>"Hope -Early Dyslexia Diagnosis System"</b><br />
  62. (Its ok. It happens to everyone) <br /><br />
  63. You new password is <b>'.$passkey.'</b><br />
  64. Your password will remain same as mentioned above until you login to the app and change the password
  65. </div>
  66. </div>
  67. <div style="clear:both; height:20px;">
  68. </div>
  69. </div>';
  70. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  71.  
  72. //Read an HTML message body from an external file, convert referenced images to embedded,
  73. //convert HTML into a basic plain-text alternative body
  74. //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  75.  
  76. if(!$mail->send()) {
  77. echo 'Message could not be sent.';
  78. echo 'Mailer Error: ' . $mail->ErrorInfo;
  79. exit;
  80. }
  81. else{
  82. echo 'Message has been sent';
  83. $sql = "UPDATE hope_users SET user_password='".encrypt($passkey)."' WHERE user_email='".$userid."'";
  84.  
  85. if (mysqli_query($con, $sql)) {
  86. echo "Record updated successfully";
  87. } else {
  88. echo "Error updating record: " . mysqli_error($con);
  89. }
  90. }
  91. }
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement