Advertisement
dadang9

errors

Aug 31st, 2018
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2. require_once 'dbcon.php';
  3. require_once 'admin/helpers/helper.php';
  4. require_once 'admin/vendors/PHPMailer/phpmailer.php';
  5.  
  6. $mail = new PHPMailer;
  7.  
  8. $email = $_POST['email_teacher'];
  9. $token = genRand(12);
  10.  
  11. if (isset($_POST['submit_email_teacher'])) {
  12.  
  13.     $send_query = " INSERT INTO teacher (email, token) VALUES ('$email', '$token') ";
  14.     $result = mysqli_query($db, $send_query) OR die(mysqli_error($db));
  15.  
  16.     $email_query = " SELECT email, token, firstname FROM teacher WHERE email = '$email'  ";
  17.     $result = mysqli_query($db, $email_query) OR die(mysqli_error($db));
  18.     $row = mysqli_fetch_assoc($result);
  19.  
  20.     try {
  21.         //Server settings
  22.         $mail->SMTPDebug = 1;                               // Enable verbose debug output
  23.         $mail->isSMTP();                                    // Set mailer to use SMTP
  24.         $mail->Host = 'smtp.gmail.com';                     // Specify main and backup SMTP servers
  25.         $mail->SMTPAuth = true;                             // Enable SMTP authentication
  26.         $mail->Username = 'dadangsukatoro@gmail.com';       // SMTP username
  27.         $mail->Password = 'sukatoro456';                    // SMTP password
  28.         $mail->SMTPSecure = 'tls';                          // Enable TLS encryption, `ssl` also accepted
  29.         $mail->Port = 587;                                  // TCP port to connect to
  30.  
  31.         //Recipients
  32.         $mail->setFrom('rekaulangkali@gmail.com', 'Admin');
  33.         $mail->addAddress($email, $row['firstname']);     // Add a recipient
  34.  
  35.         //Content
  36.         $mail->isHTML(true);                                  // Set email format to HTML
  37.         $mail->Subject = 'Here is the subject';
  38.         $mail->Body    = $row['token'];
  39.         $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  40.  
  41.         $mail->send();
  42.         echo 'Message has been sent';
  43.     } catch (Exception $e) {
  44.         echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement