-
Notifications
You must be signed in to change notification settings - Fork 3
/
mail.php
48 lines (43 loc) · 1.52 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
<?php
if($_POST)
{
//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
//exit script outputting json data
$output = json_encode(
array(
'type'=>'error',
'text' => 'Request must come from Ajax'
));
die($output);
}
//check $_POST vars are set, exit if any missing
if(!isset($_POST["name"]) || !isset($_POST["email"]) || !isset($_POST["message"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Input fields are empty!'));
die($output);
}
$name = $_POST["name"];
$email= $_POST["email"];
$text= $_POST["message"];
$headers .= 'Bcc: [email protected]' . "\r\n";
//$headers .= 'Bcc: [email protected]' . "\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $email . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message ='<table style="width:100%">
<tr><td>Name: '.$name.'</td></tr>
<tr><td>Email: '.$email.'</td></tr>
<tr><td>Message: '.$text.'</td></tr>
</table>';
$to_mail= '[email protected]';
$sentMail = @mail($to_mail, $subject, $message, $headers);
if(!$sentMail)
{
$output = json_encode(array('type'=>'error', 'text' => '❌ Could not send mail! Please check your PHP mail configuration.'));
die($output);
}
$output = json_encode(array('type'=>'message', 'text' => '✔️ Your message has been sent.'));
die($output);
}
?>