I have build a PHP contact form with validation which works fine . But receiving problem. when submit i receive email but it is showing wrong email address in from area. I want to show my actual address. Here is live link http://www.luxpress.co.uk/checking/contact_form.php when you submit enter your own email address you will receive confirmation email also. check what i receive in from area. from: 2.secureserver.net to: date: Wed, Aug 31, 2016 at 12:38 AM I want to show Here is my PHP validation form code <?php // Initialize variables to null. $name =""; //Sender Name $email =""; //Sender's email ID $purpose =""; //Subject of mail $message =""; //Sender's Message $nameError =""; $emailError =""; $purposeError =""; $messageError =""; $successMessage =""; // Additional headers $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n"; //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 message if (empty($_POST["email"])) { $emailError = "Email is required"; } else { $email = test_input($_POST["email"]); } // checking null values in message if (empty($_POST["purpose"])) { $purposeError = "Purpose is required"; } else { $purpose = test_input($_POST["purpose"]); } // checking null values in message if (empty($_POST["message"])) { $messageError = "Message is required"; } else { $message = test_input($_POST["message"]); } // checking null values in all fields if( !($name=='') && !($email=='') && !($purpose=='') &&!($message=='') ) {// checking valid email if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $header= $name."<". $email .">"; $headers = "CONTACT FORM"; /* Let's prepare the message for the e-mail */ $msg = "Hello! $name Thank you...! For Contacting Us. Name: $name E-mail: $email Purpose: $purpose Message: $message This is a Contact Confirmation mail. We Will contact You as soon as possible."; $msg1 = " $name Contacted Us. Here are some information about $name. Name: $name E-mail: $email Purpose: $purpose Message: $message "; /* Send the message using mail() function */ if(mail($email, $headers, $msg ) && mail("kuhashmi@gmail.com", $header, $msg1 )) { $successMessage = "Thank you and that Red Dragon Digital Services received their enquiry and someone will get back to them."; } } else { $emailError = "Invalid Email"; } } } // function for filtering input values function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> PHP:
Well... You're not at all using the From: header, so I'd suggest adding it, with the email you want to send from. Also, you're using quite a bit of regex to get heck email - php has gotten a FILTER function which can do this for you.
Thanks for your reply. Can you plz guide me or help to write header code. Because i have very little idea about header. I appreciate if you paste the code here for header so i can use it properly.