-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact-mail.php
51 lines (39 loc) · 1.84 KB
/
contact-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
<!-- AUTHORS: WAN LI AND NATALIE ZHANG -->
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 0; // 1 = Enable verbose debug output. 2 = message only. 0 = nothing. only confirm message
$mail->SMTPAuth = TRUE; // Enable SMTP authentication
$mail->SMTPSecure = "tls"; // Enable TLS encryption, 'ssl' (a predecessor to TSL) is also accepted
$mail->Port = 587; // TCP port to connect to (587 is a standard port for SMTP)
$mail->Host = "smtp.gmail.com"; // Specify main and backup SMTP servers
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "insert password"; // SMTP password
//Recipient
$mail->setFrom('[email protected]', 'NatAndWan');
$mail->addAddress($_POST['email']);
$mail->isHTML(true);
$mail->Subject = 'Contact Us';
$mail->Body = 'From=' . $_POST['name'] . ': email address=' . $_POST['email'] . ': comment=' . $_POST['comment'];
$mail->send();
// Send to website's email
$mail->setFrom('[email protected]', 'NatAndWan');
$mail->addAddress('[email protected]');
$mail->isHTML(true);
$mail->Subject = 'Contact Us';
$mail->Body = 'From=' . $_POST['name'] . ': email address=' . $_POST['email'] . ': comment=' . $_POST['comment'];
$mail->send();
$confirm = "Thank you. Your comment has been sent. You will be redirected to the home page in 1 seconds.";
echo '<div class ="center confirm">' . $confirm . '</div>';
header('refresh:1; url=home.php');
} catch (Exception $e) {
$msg = "sorry it was not sent.";
}
?>