简体   繁体   English

当我在电子邮件联系表单上点击“提交”时,显示代码

[英]code displays when i hit submit on my email contact form

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. 因此,我认为这不是表单页面,而是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. 我将其放在pastebin而不是此处,因为我无法获取正确格式化的代码。 http://pastebin.com/VFN7epGx 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']) || 添加else语句并使用echo代替dead可能会有所帮助: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. 我无法使用pastebin,因为它似乎已被删除,但我会这样亲自编写-并添加preg_replace()代码以清理输入。 Make sure that nothing has accidentally closed the php tag and that there is no JavaScript hanging around outside of script tags. 确保没有任何东西意外关闭了php标记,并且没有JavaScript悬挂在脚本标记之外。

     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 我喜欢@ T.Somers所做的工作,以清理他在输入提交时丢失其值的PHP Code上的输入

and this explains preg_replace quite well 这很好地解释了preg_replace

Regular Expression clean method PHP by @CodeCaster 正则表达式清理方法PHP by @CodeCaster

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM