roldahayes Posted August 11, 2011 Share Posted August 11, 2011 Hi, I am trying to add a "telephone" field to a contact form. I have added it to the output email but this comes back blank where the telephone number should be. Where do I need to add the $_POST for the telephone field? <?php $to = "admin@mysite.com"; // Replace with your email address $subject = "Message from ".ucwords($_POST['name']); // Enter the subject here. //Validating email addres $email = $_POST['email']; function validateEmail($email) { if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$', $email)) return true; else return false; } //Validates the required fields if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['message']) < 1 ) || validateEmail($email) == FALSE){ $emailerror .= true; } else { $emailerror .= false; //Composing the email $email_message = "Name: " . ucwords($_POST['name']) . "\n" . "Email: " . $email . "\n" . "Telephone: " . $telephone . "\n" . "Message: " . "\n" . $_POST['message'] . "\n"; //Assigning the REPLY FUNCTION $headers = "From: CONTACTFORM@admin@mysite.com\r\n"; $headers .= "Reply-To: " . $email . "\n" ; //Sending the email mail($to, $subject, $email_message, $headers); } ?> <?php if($emailerror == true) { echo '<span>Please fill all the fields correctly.</span>'; } else { echo "<span>Message has been sent. Thank you!</span>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244482-adding-a-new-field-to-contact-form/ Share on other sites More sharing options...
WebStyles Posted August 11, 2011 Share Posted August 11, 2011 I don't see your form in the code, so I don't know what name you gave to the field. Assuming it's name="telephone", change this: "Telephone: " . $telephone . "\n" . to this: "Telephone: " . $_POST['telephone'] . "\n" . Quote Link to comment https://forums.phpfreaks.com/topic/244482-adding-a-new-field-to-contact-form/#findComment-1255738 Share on other sites More sharing options...
roldahayes Posted August 11, 2011 Author Share Posted August 11, 2011 Excellent, thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/244482-adding-a-new-field-to-contact-form/#findComment-1255758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.