· 7 years ago · Aug 31, 2018, 07:12 AM
1<?php
2require_once 'dbcon.php';
3require_once 'admin/helpers/helper.php';
4require_once 'admin/vendors/PHPMailer/phpmailer.php';
5
6$mail = new PHPMailer;
7
8$email = $_POST['email_teacher'];
9$token = genRand(12);
10
11if (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;smtp2.example.com'; // Specify main and backup SMTP servers
25 $mail->SMTPAuth = true; // Enable SMTP authentication
26 $mail->Username = '*********@gmail.com'; // SMTP username
27 $mail->Password = '***********'; // 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}