forked from LibrarySimplified/library-simplified-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactform.php
executable file
·30 lines (26 loc) · 1.01 KB
/
contactform.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
<?php
function customValidation($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$to = '[email protected]'; // Recipient's email address
$name = customValidation($_REQUEST['name']); // Sender's name
$subject = customValidation($_REQUEST['subject']); // Email subject
$email = customValidation($_REQUEST['email']); // Sender's email address
$message = customValidation($_REQUEST['message']); // Contact form message
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "invalidEmailAddress"; // invalid email address
return false;
}
else {
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Reply-to: ".$email."\r\n";
$headers .= "From: ". $name ." <" . $email . ">\r\n"; // Sender's email address
mail($to, $subject, $message, $headers);
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
}
?>