-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
226 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
if (isset($_POST['email'])) { | ||
|
||
$email_to = "[email protected]"; | ||
$email_subject = "You've got a new submission"; | ||
|
||
function problem($error) | ||
{ | ||
echo "Oh looks like there is some problem with your form data: <br><br>"; | ||
echo $error . "<br><br>"; | ||
echo "Please fix those to proceed.<br><br>"; | ||
die(); | ||
} | ||
|
||
if ( | ||
!isset($_POST['fullName']) || | ||
!isset($_POST['email']) || | ||
!isset($_POST['message']) | ||
) { | ||
problem('Oh looks like there is some problem with your form data.'); | ||
} | ||
|
||
$name = $_POST['fullName']; | ||
$email = $_POST['email']; | ||
$message = $_POST['message']; | ||
|
||
$error_message = ""; | ||
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; | ||
|
||
if (!preg_match($email_exp, $email)) { | ||
$error_message .= 'Email address does not seem valid.<br>'; | ||
} | ||
|
||
$string_exp = "/^[A-Za-z .'-]+$/"; | ||
|
||
if (!preg_match($string_exp, $name)) { | ||
$error_message .= 'Name does not seem valid.<br>'; | ||
} | ||
|
||
if (strlen($message) < 6) { | ||
$error_message .= 'Message should not be less than 6 characters<br>'; | ||
} | ||
|
||
if (strlen($error_message) > 0) { | ||
problem($error_message); | ||
} | ||
|
||
$email_message = "Form details following:\n\n"; | ||
|
||
function clean_string($string) | ||
{ | ||
$bad = array("content-type", "bcc:", "to:", "cc:", "href"); | ||
return str_replace($bad, "", $string); | ||
} | ||
|
||
$email_message .= "Name: " . clean_string($name) . "\n"; | ||
$email_message .= "Email: " . clean_string($email) . "\n"; | ||
$email_message .= "Message: " . clean_string($message) . "\n"; | ||
|
||
$headers = 'From: ' . $email . "\r\n" . | ||
'Reply-To: ' . $email . "\r\n" . | ||
'X-Mailer: PHP/' . phpversion(); | ||
@mail($email_to, $email_subject, $email_message, $headers); | ||
?> | ||
|
||
Thank you for your response, we will get back to you shortly. Keep an eye out for our email: [email protected] | ||
|
||
<?php | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters