-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendEmail.php
40 lines (33 loc) · 1.27 KB
/
sendEmail.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
if (isset($_POST['name']) && isset($_POST['email'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['body'];
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/SMTP.php";
require_once "PHPMailer/Exception.php";
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "<YOUR EMAIL>";
$mail->Password = '<YOUR PASSWORD>';
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
$mail->isHTML(true);
$mail->setFrom($email, $name);
$mail->addAddress("vineetkia@gmail.com");
$mail->Subject = $subject;
$mail->Body = '<h3 align=left>NAME: '.$_POST['name'].'<br><br>EMAIL: '.$_POST['email'].'<br><br>MESSAGE: '.$_POST['body'].'</h3>';
if ($mail->send()) {
$status = "success";
$response = "[--<> Email Sent Successfully <>--]";
} else {
$status = "failed";
$response = "Something is wrong: <br><br>" . $mail->ErrorInfo;
}
exit(json_encode(array("status" => $status, "response" => $response)));
}
?>