Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once "connect.php";
- include "crypt.php";
- require 'mailer/PHPMailerAutoload.php';
- if (mysqli_connect_errno($con))
- {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
- $userid = $_POST['userkey'];
- //$userid = 'vthakkar1994@gmail.com';
- $result = mysqli_query($con,"SELECT * FROM hope_users where user_email='$userid'");
- $row = mysqli_fetch_array($result);
- $count = mysqli_num_rows($result);
- $usernme = $row[2]." ".$row[3];
- $passkey = randomPassword();
- $data = $usernme." ".$passkey;
- function randomPassword() {
- $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
- $pass = array(); //remember to declare $pass as an array
- $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
- for ($i = 0; $i < 8; $i++) {
- $n = rand(0, $alphaLength);
- $pass[] = $alphabet[$n];
- }
- return implode($pass); //turn the array into a string
- }
- if ($count > 0){
- }
- if ($userid)
- {
- $mail = new PHPMailer;
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'smtp.gmail.com'; // Specify main and backup server
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'hope.dyslexiaapp@gmail.com'; // SMTP username
- $mail->Password = 'hopemyapp'; // SMTP password done
- $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
- $mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
- $mail->setFrom('hope.dyslexiaapp@gmail.com', 'Dyslexia App'); //Set who the message is to be sent from
- $mail->addReplyTo('hope.dyslexiaapp@gmail.com', 'Dyslexia App'); //Set an alternative reply-to address
- $mail->addAddress($userid); // Name is optional
- $mail->WordWrap = 50; // Set word wrap to 50 characters
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = '"Hope" - Password Recovery System';
- $mail->Body = '<div style="border:solid thin #903; width:600px; height: 200px;margin:30px; background-color:#FCF;">
- <div style="text-align:center;width: 15%; float:left;" >
- <img src="http://oi58.tinypic.com/5wdw0x.jpg" style="max-width:50px; margin:20px;"/>
- </div>
- <div style="text-align:center; width:80%; float:left;">
- <div style="text-align:left;">
- <h2>Hope - Password Recovery System</h2>
- </div>
- <div style="text-align:left;font-size:12px;">
- Hello <b>'.$usernme.',</b> <br />
- You have requested to get your password reset for <br /><b>"Hope -Early Dyslexia Diagnosis System"</b><br />
- (Its ok. It happens to everyone) <br /><br />
- You new password is <b>'.$passkey.'</b><br />
- Your password will remain same as mentioned above until you login to the app and change the password
- </div>
- </div>
- <div style="clear:both; height:20px;">
- </div>
- </div>';
- $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- //Read an HTML message body from an external file, convert referenced images to embedded,
- //convert HTML into a basic plain-text alternative body
- //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
- if(!$mail->send()) {
- echo 'Message could not be sent.';
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- exit;
- }
- else{
- echo 'Message has been sent';
- $sql = "UPDATE hope_users SET user_password='".encrypt($passkey)."' WHERE user_email='".$userid."'";
- if (mysqli_query($con, $sql)) {
- echo "Record updated successfully";
- } else {
- echo "Error updating record: " . mysqli_error($con);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement