I am trying to get my simple contact form to work. When it hit submit to send the email, it just shows code of the next page. So i am thinking it is not the form page but the send_form_email.php. Please help me get this code working, i am not sure what i am missing here. I have tried editing the code to work but it is not changing the output. I have put it in pastebin instead of here because i could not get the code to format correctly. http://pastebin.com/VFN7epGx
if(
!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
//i think it may have to do with this
Adding an else statement and using echo instead of dead might help: if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
echo('We are sorry, but there appears to be a problem with the form you submitted.');
} else {
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
}
Sorry fpr the bad formatting, i'm on my phone. Tomorrow I'll look into this on my computer if you didn't fix it yet.
I can't get at the pastebin as it seems to have been removed, but would personally write it like this - and add preg_replace() code to clean up the inputs. Make sure that nothing has accidentally closed the php tag and that there is no JavaScript hanging around outside of script tags.
if( !isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) {
echo 'We are sorry, but there appears to be a problem with the form you submitted.';
}else{
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
}
I like what @T.Somers has done to clean up his inputs on PHP Code losing its values when I hit submit
and this explains preg_replace quite well
Regular Expression clean method PHP by @CodeCaster
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.