-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
69 lines (52 loc) · 1.72 KB
/
index.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
64
65
66
67
68
69
<?php
error_reporting(0);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
require "email_config.php";
$headers = getallheaders();
$http_origin = $_SERVER['HTTP_ORIGIN'];
if (in_array($http_origin, $allowed_host)) {
if (isset($_REQUEST["subject"]) && isset($_REQUEST["message"])) {
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = $smtp_host;
$mail->Username = $your_gmail;
$mail->Password = $app_password; //your app password
$mail->IsHTML(true);
$mail->AddAddress($setmail);
$mail->SetFrom($your_gmail, $your_name);
$mail->Subject = $_REQUEST["subject"];
$content = "<b>" . $_REQUEST["message"] . "</b>";
$mail->MsgHTML($content);
if (!$mail->Send()) {
$status = ["status" => "failed"];
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET , POST');
header('Content-Type: application/json; charset=utf-8');
echo json_encode($status, true);
} else {
$status = ["status" => "success"];
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET , POST');
header('Content-Type: application/json; charset=utf-8');
echo json_encode($status, true);
}
}
else {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
exit;
}
}
else {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
exit;
}
?>