-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmail.php
49 lines (41 loc) · 1.72 KB
/
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
<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//required files
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
//Create an instance; passing `true` enables exceptions
if (isset($_POST["send"])) {
$mail = new PHPMailer(true);
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = '[email protected]'; //SMTP write your email
$mail->Password = 'jtvbusyczflzxtty'; //SMTP password
$mail->SMTPSecure = 'ssl'; //Enable implicit SSL encryption
$mail->Port = 465;
//Recipients
$mail->setFrom( $_POST["email"], $_POST["name"]); // Sender Email and name
$mail->addAddress('[email protected]'); //Add a recipient email
$mail->addReplyTo($_POST["email"], $_POST["name"]); // reply to sender email
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->CharSet = 'UTF-8'; //Set the character set
$mail->FromName = $_POST["name"]; // sender name
$mail->Subject = $_POST["subject"]; // email subject headings
$mail->Body = $_POST["message"]; //email message
// Success sent message alert
$mail->send();
echo
"
<script>
alert('Message was sent successfully!');
document.location.href = 'index.php';
</script>
";
}
?>