Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'dbcon.php';
- require_once 'admin/helpers/helper.php';
- require_once 'admin/vendors/PHPMailer/phpmailer.php';
- $mail = new PHPMailer;
- $email = $_POST['email_teacher'];
- $token = genRand(12);
- if (isset($_POST['submit_email_teacher'])) {
- $send_query = " INSERT INTO teacher (email, token) VALUES ('$email', '$token') ";
- $result = mysqli_query($db, $send_query) OR die(mysqli_error($db));
- $email_query = " SELECT email, token, firstname FROM teacher WHERE email = '$email' ";
- $result = mysqli_query($db, $email_query) OR die(mysqli_error($db));
- $row = mysqli_fetch_assoc($result);
- try {
- //Server settings
- $mail->SMTPDebug = 1; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'dadangsukatoro@gmail.com'; // SMTP username
- $mail->Password = 'sukatoro456'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587; // TCP port to connect to
- //Recipients
- $mail->setFrom('rekaulangkali@gmail.com', 'Admin');
- $mail->addAddress($email, $row['firstname']); // Add a recipient
- //Content
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Here is the subject';
- $mail->Body = $row['token'];
- $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- $mail->send();
- echo 'Message has been sent';
- } catch (Exception $e) {
- echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement