-
-
Save crazyboy24/0dc44d3440cee8de6150 to your computer and use it in GitHub Desktop.
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
<?php phpinfo();// Initialize variables to null. | |
$name =""; // Sender Name | |
$email =""; // Sender's email ID | |
$message =""; // Sender's Message | |
$subject =implode($subject, "\n"); // Sender's Subject | |
$subjectError =""; | |
$nameError =""; | |
$emailError =""; | |
$messageError =""; | |
$successMessage =""; // On submitting form below function will execute. | |
if(isset($_POST['submit'])) { // Checking null values in message. | |
if (empty($_POST["name"])){ | |
$nameError = "Name is required"; | |
} | |
else | |
{ | |
$name = test_input($_POST["name"]); // check name only contains letters and whitespace | |
if (!preg_match("/^[a-zA-Z ]*$/",$name)) | |
{ | |
$nameError = "Only letters and white space allowed"; | |
} | |
} // Checking null values in the message. | |
if (empty($_POST["email"])) | |
{ | |
$emailError = "Email is required"; | |
} | |
else | |
{ | |
$email = test_input($_POST["email"]); | |
} // Checking null values in message. | |
if (empty($_POST["message"])) | |
{ | |
$messageError = "Message is required"; | |
} | |
else | |
{ | |
$message = test_input($_POST["message"]); | |
} | |
// Checking null values in the message. | |
if (empty($_POST["subject"])) | |
{ | |
$subjectError = "Subject is required"; | |
} | |
else | |
{ | |
$message = test_input($_POST["subject"]); | |
} | |
// Checking null values in the subject. | |
if( !($name=='') && !($email=='') &&!($message=='') && !($subject=='') ) | |
{ // Checking valid email. | |
if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) | |
{ | |
$header= $name."<". $email .">".$subject; | |
$headers = "My header here"; | |
if(mail($email, $headers, $msg ) && mail("myemailid", $header, $msg1 )) | |
{ | |
$successMessage = "Message sent successfully. You will be contacted soon."; | |
} | |
} | |
else | |
{ $emailError = "Invalid Email"; | |
} | |
} | |
} // Function for filtering input values. function test_input($data) | |
{ | |
$data = trim($data); | |
$data = stripslashes($data); | |
$data = htmlspecialchars($data); | |
return $data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment