-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.php
66 lines (52 loc) · 2.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
include ('credential.php');
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['message'])){
$name=$_POST["name"];
$email=$_POST["email"];
$subject="[From : ";
$subject .=$email;
$subject .=" ] ";
$subject .=$_POST["subject"];
$message=$_POST["message"];
$to ="[email protected]";
//$to =EMAIL;
require_once 'PHPMailer/PHPMailer.php';
require_once 'PHPMailer/SMTP.php';
require_once 'PHPMailer/Exception.php';
$mail = new PHPMailer(true);
$mail->SMTPDebug = 2; // Enable verbose debug output
//SMTP Settings
//$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $gmail_id; // SMTP username
$mail->Password = $gmail_pw; // SMTP password
$mail->Port = 465;//587; // TCP port to connect to
$mail->SMTPSecure = "ssl"; //'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->CharSet = "utf-8";
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Email Settings
$mail->setFrom($email,$name);
$mail->addAddress($to); // Add a recipient
$mail->addReplyTo($to);
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject =$subject;
$mail->Body =$message;
if($mail->send()) {
$response="success";
} else {
$response= "Something is wrong: " . $mail->ErrorInfo;
}
exit(json_encode(array("response" => $response)));
}
?>