-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax-email.php
43 lines (34 loc) · 1.13 KB
/
ajax-email.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
<?php
/* SETTINGS */
$recipient = "[email protected]";
$subject = "New Message from Contact Form";
if($_POST){
/* DATA FROM HTML FORM */
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//$phone = $_POST['phone'];
/* SUBJECT */
$emailSubject = $subject . " by " . $name;
/* HEADERS */
$headers = "From: $name <$email>\r\n" .
"Reply-To: $name <$email>\r\n" .
"Subject: $emailSubject\r\n" .
"Content-type: text/plain; charset=UTF-8\r\n" .
"MIME-Version: 1.0\r\n" .
"X-Mailer: PHP/" . phpversion() . "\r\n";
/* PREVENT EMAIL INJECTION */
if ( preg_match("/[\r\n]/", $name) || preg_match("/[\r\n]/", $email) ) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
die("500 Internal Server Error");
}
/* MESSAGE TEMPLATE */
$mailBody = "Name: $name \n\r" .
"Email: $email \n\r" .
"Subject: $subject \n\r" .
// "Phone: $phone \n\r" .
"Message: $message";
/* SEND EMAIL */
mail($recipient, $emailSubject, $mailBody, $headers);
}
?>