Advertisement
Guest User

Untitled

a guest
May 11th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.75 KB | None | 0 0
  1. <?php
  2.  
  3. // Incluimos las librerías de PHPMailer require 'lib/PHPMailer/PHPMailerAutoload.php';
  4.  
  5. $error=''; // Variable To Store Error Message
  6.  
  7. if (isset($_POST['recovery_mail'])) {
  8.  
  9.     if (empty($_POST['recovery_mail'])) {
  10.  
  11.         $error = "Ingresa un correo electrónico";
  12.        
  13.     } else {
  14.  
  15.         $email = $_POST['recovery_mail'];
  16.  
  17.         // Establishing Connection with Server by passing server_name, user_id and password as a parameter
  18.         require_once('avena_db_connect.php');
  19.  
  20.         // To protect MySQL injection for Security purposes
  21.         $clean_email = stripslashes($email);
  22.  
  23.         // SQL query to fetch information of registerd users and finds user match.
  24.         $query = $con->query("SELECT email FROM users WHERE email = '$clean_email'");
  25.         $rows = $query->fetch(PDO::FETCH_ASSOC);
  26.  
  27.         if ($rows['email'] == $clean_email) {
  28.            
  29.             $length = 32;
  30.             $token = bin2hex(random_bytes($length));
  31.  
  32.             $query = $con->query("INSERT INTO user_recovery('$clean_mail', '$token', CURDATE()) VALUES (user_mail, user_key, exp_date)");
  33.  
  34.  
  35.             //Create a new PHPMailer instance
  36. $mail = new PHPMailer;
  37. //Tell PHPMailer to use SMTP
  38. $mail->isSMTP();
  39. //Enable SMTP debugging
  40. // 0 = off (for production use)
  41. // 1 = client messages
  42. // 2 = client and server messages
  43. $mail->SMTPDebug = 2;
  44. //Ask for HTML-friendly debug output
  45. $mail->Debugoutput = 'html';
  46. //Set the hostname of the mail server
  47. $mail->Host = "mail.example.com";
  48. //Set the SMTP port number - likely to be 25, 465 or 587
  49. $mail->Port = 25;
  50. //Whether to use SMTP authentication
  51. $mail->SMTPAuth = true;
  52. //Username to use for SMTP authentication
  53. $mail->Username = "yourname@example.com";
  54. //Password to use for SMTP authentication
  55. $mail->Password = "yourpassword";
  56. //Set who the message is to be sent from
  57. $mail->setFrom('from@example.com', 'First Last');
  58. //Set an alternative reply-to address
  59. $mail->addReplyTo('replyto@example.com', 'First Last');
  60. //Set who the message is to be sent to
  61. $mail->addAddress('whoto@example.com', 'John Doe');
  62. //Set the subject line
  63. $mail->Subject = 'PHPMailer SMTP test';
  64. //Read an HTML message body from an external file, convert referenced images to embedded,
  65. //convert HTML into a basic plain-text alternative body
  66. $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  67. //Replace the plain text body with one created manually
  68. $mail->AltBody = 'This is a plain-text message body';
  69. //Attach an image file
  70. $mail->addAttachment('images/phpmailer_mini.png');
  71. //send the message, check for errors
  72. if (!$mail->send()) {
  73.     echo "Mailer Error: " . $mail->ErrorInfo;
  74. } else {
  75.     echo "Message sent!";
  76. }          
  77.  
  78.  
  79.         } else { $error = "Datos incorrectos."; }
  80.  
  81.     }
  82.  
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement