-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_mail.php
63 lines (54 loc) · 1.4 KB
/
send_mail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<script src='https://cdn.jsdelivr.net/npm/sweetalert2@10'></script>
<title>Send mail</title>
</head>
<body>
<?php
session_start();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$email = $_POST['email'];
$mail = new PHPMailer();
$otp=0;
try {
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com;';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = '123@Kb1530';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('[email protected]', 'Note Keeper');
$mail->addAddress($email);
$otp=rand(1000,9999);
$mail->isHTML(true);
$mail->Subject = 'Subject';
$mail->Body = '<b>OTP: </b> '.$otp;
if($mail->send()){
$_SESSION['email']=$email;
$_SESSION['otp']=$otp;
$str = "
<script type='text/javascript'>
Swal.fire(
'OTP has been sent',
'Please check $email',
'success'
).then(function() {
window.location.href = 'check_otp.php';
})
</script>
";
echo $str;
}
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
</body>
</html>