-
Notifications
You must be signed in to change notification settings - Fork 1
/
mail.php
86 lines (74 loc) · 2.82 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
require("vendor/phpmailer/phpmailer/src/PHPMailer.php");
require("vendor/phpmailer/phpmailer/src/SMTP.php");
$secretKey = "your_private_key";
$responseKey = $_POST['g-recaptcha-response'];
$userIP = $_SERVER['REMOTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
$response = file_get_contents($url);
$response = json_decode($response);
if(isset($_POST['submit'])){
$mail = new PHPMailer\PHPMailer\PHPMailer();
if($response -> success) {
//From email address and name
$mail->From = "info@example.com";
$mail->FromName = "Enquiry";
//To address and name
$mail->addAddress("example@gmail.com");
$mail->addAddress("example@gmail.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo($_POST['email'], "Reply");
//CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Enquiry From example.com";
$mail->Body = "<html>
<head>
<title>HTML email</title>
</head>
<body>
<table>
<tr>
<td><strong>Full Name</strong></td><td>:</td><td>".$_POST['name']."</td>
</tr>
<tr>
<td><strong>Email ID</strong></td><td>:</td><td>".$_POST['email']."</td>
</tr>
<tr>
<td><strong>Subject</strong></td><td>:</td><td>".$_POST['subject']."</td>
</tr>
<tr>
<td><strong>Mobile</strong></td><td>:</td><td>".$_POST['mobile']."</td>
</tr>
<tr>
<td><strong>Message</strong></td><td>:</td><td>".$_POST['message']."</td>
</tr>
</table>
</body>
</html>";
$mail->AltBody = "This is the plain text version of the email content for Testing.";
if(!$mail->send())
{
echo "<script>
alert('Sorry mail was not send due to some server problem, please try again later!');
window.history.back();
</script>";
// echo $mail->ErrorInfo;
}
else
{
echo "<script>
alert('Email Sent Successfully!');
window.history.back();
</script>";
}
} else {
echo "<script>
alert('Please Check the recaptcha and Try again');
window.history.back();
</script>";
}
}
?>