-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactformhandler.php
executable file
·38 lines (32 loc) · 1.31 KB
/
contactformhandler.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
<?php
// Define some constants
define( "RECIPIENT_NAME", "Lieven Vandiest" ); //UPDATE THIS TO YOUR NAME
define( "RECIPIENT_EMAIL", "[email protected]" ); //UPDATE THIS TO YOUR EMAIL ID
define( "EMAIL_SUBJECT", "Website Visitor Message" ); //UPDATE THIS TO YOUR SUBJECT
// Read the form values
$success = false;
$senderName = isset( $_POST['name'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['name'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$original_message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
$message = 'Name: '.$senderName.'<br/>Email: '.$senderEmail.'<br/>Message: '.$original_message;
// If all values exist, send the email
if ( $senderName && $senderEmail && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n";
$success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );
}
if ( $success )
{
?>
<script>
window.location='thanks.html';
</script>
<?php
}
else
{
echo "<h1>There was a problem sending your message. Please try again.</h1>";
}
?>