PHP联系表单电子邮件到电子邮件地址,但'名称'字段为空? [英] PHP contact form emails to the email address, but 'name' field is empty?
问题描述
不,我是新手!
我已经成功设置了一个联系表单页面。它通过电子邮件发送表单字段中的'电子邮件地址'和'消息',但不发送名称字段值,它只是空白。
我看不到在哪里我出错了。所有字段名称都匹配到PHP文件。任何想法我做错了什么?
以下是我的代码:
< form id =form_28name =website_queryaction =mailform2.phpaccept-charset =UTF-8method =posttarget =_ selfenctype =multipart / form -datastyle =margin:0; position:absolute; left:231px; top:242px; width:343px; height:229px; / * MainDivStyle * /__AddCode =here>
<! - MainDivStart - >
<! - HTML框架 - 名称txt_31 - >
<! - 序言 - >
< div style =position:absolute; left:8px; top:8px; width:51px; height:18px; overflow:hidden; / * BorderDivStyle * /__AddCode =InsideBorderDiv>
<! - BorderDivContents - >
< p class =Wp-Body-P>< label for =edit_1>< span class =Body-C> name< / span>< / label> < / p为H.
< / div>
<! - Postamble - >
<! - 表单编辑框edit_1 - >
<! - 序言 - >
< input type =textid =edit_1name =namevalue =style =position:absolute; left:103px; top:8px; width:50px; / * Tag Style * /__AddCode =here>
<! - Postamble - >
<! - HTML框架 - 电子邮件txt_32 - >
<! - 序言 - >
< div style =position:absolute; left:8px; top:38px; width:51px; height:18px; overflow:hidden; / * BorderDivStyle * /__AddCode =InsideBorderDiv>
<! - BorderDivContents - >
< p class =Wp-Body-P>< label for =edit_19>< span class =Body-C>电子邮件< / span>< / label> < / p为H.
< / div>
<! - Postamble - >
<! - 表单编辑框edit_19 - >
<! - 序言 - >
< input type =textid =edit_19name =emailvalue =style =position:absolute; left:103px; top:38px; width:50px; / * Tag Style * /__AddCode =here>
<! - Postamble - >
<! - HTML Frame - message txt_33 - >
<! - 序言 - >
< div style =position:absolute; left:8px; top:68px; width:79px; height:18px; overflow:hidden; / * BorderDivStyle * /__AddCode =InsideBorderDiv>
<! - BorderDivContents - >
< p class =Wp-Body-P>< label for =text_2>< span class =Body-C> message< / span>< / label> < / p为H.
< / div>
<! - Postamble - >
<! - Text Area text_2 - >
<! - 序言 - >
<! - Postamble - >
<! - HTML框架 - captcha txt_34 - >
<! - 序言 - >
< div style =position:absolute; left:8px; top:114px; width:69px; height:18px; overflow:hidden; / * BorderDivStyle * /__AddCode =InsideBorderDiv>
<! - BorderDivContents - >
< p class =Wp-Body-P>< label for =captcha_1>< span class =Body-C> captcha< / span>< / label> < / p为H.
< / div>
<! - Postamble - >
<! - 表单验证码captcha_1 - >
<! - 序言 - >
< div style =position:absolute; left:103px; top:114px; width:190px; height:69px; / * MainDivStyle * /__AddCode =here>
<! - MainDivStart - >
< img src =http://www.serifwebresources.com/util/img_verify.php?gen_word=1&id=captcha_1>< br>< input type =textid = captcha_1name =captcha_1size =20__AddCode =here>
< / div>
<! - Postamble - >
<! - 表单按钮butn_4 - >
<! - 序言 - >
< input type =submitstyle =position:absolute; left:8px; top:191px; width:81px; height:22px; / * Tag Style * /value =Submit__AddCode =这里>
<! - Postamble - >
< / form>
PHP代码(mailform2.php):
<?php
$ errors ='';
$ myemail ='myemail'; //< -----把你的电子邮件地址放在这里。
if(empty($ _ POST ['name'])||
empty($ _ POST ['email'])||
empty($ _ POST ['message']))
$ name = $ _POST ['name'];
$ email = $ _POST ['email'];
$ message = $ _POST ['message'];
if(empty($ errors))
{
$ to = $ myemail;
$ email_subject =网站查询:$ name;
$ email_body =您收到了一条新消息。
以下是详细信息:\ n名称:$ name \\\
Email:$ email \\\
Message \\\
$ message;
$ headers =From:$ myemail\\\
;
$ headers。=回复:$ email;
邮件($ to,$ email_subject,$ email_body,$ headers);
//重定向到'thank you'页面
header('Location:contact-form-thank-you.html');
}
?>
if empty($ _ POST ['name'])||
empty($ _ POST ['email'])||
empty($ _ POST ['message']))
$ name = $ _POST ['name'];
在上面的代码中,如果邮局的名称,电子邮件和邮件为空,那么它将name = $ _POST [ 'name'];
没有设置SO $ name变量。
所以像这些代码$ b $
if(empty($ _ POST ['name'])||
empty($ _ POST ['email'])||
empty($ _ POST ['message'])){
$ errors ='请输入所有必填字段';
}
else
{
$ name = $ _POST ['name'];
$ email = $ _POST ['email'];
$ message = $ _POST ['message'];
}
No, I am new to this form!
I have successfully set up a contact form page. It emails me the 'email address' and 'message' from the form fields, but does not send the name filed value, it is just blank.
I cannot see where I have gone wrong. All the field names match up to the PHP file. Any ideas as to what I'm doing wrong?
Here is my code:
<form id="form_28" name="website_query" action="mailform2.php" accept-charset="UTF-8" method="post" target="_self" enctype="multipart/form-data" style="margin:0;position:absolute;left:231px;top:242px;width:343px;height:229px; /*MainDivStyle*/" __AddCode="here">
<!--MainDivStart-->
<!-- HTML Frame - name txt_31 -->
<!--Preamble-->
<div style="position:absolute;left:8px;top:8px;width:51px;height:18px;overflow:hidden; /*BorderDivStyle*/" __AddCode="InsideBorderDiv">
<!--BorderDivContents-->
<p class="Wp-Body-P"><label for="edit_1"><span class="Body-C">name</span></label></p>
</div>
<!--Postamble-->
<!-- Form Edit box edit_1 -->
<!--Preamble-->
<input type="text" id="edit_1" name="name" value="" style="position:absolute; left:103px; top:8px; width:50px; /*Tag Style*/" __AddCode="here">
<!--Postamble-->
<!-- HTML Frame - email txt_32 -->
<!--Preamble-->
<div style="position:absolute;left:8px;top:38px;width:51px;height:18px;overflow:hidden; /*BorderDivStyle*/" __AddCode="InsideBorderDiv">
<!--BorderDivContents-->
<p class="Wp-Body-P"><label for="edit_19"><span class="Body-C">email</span></label></p>
</div>
<!--Postamble-->
<!-- Form Edit box edit_19 -->
<!--Preamble-->
<input type="text" id="edit_19" name="email" value="" style="position:absolute; left:103px; top:38px; width:50px; /*Tag Style*/" __AddCode="here">
<!--Postamble-->
<!-- HTML Frame - message txt_33 -->
<!--Preamble-->
<div style="position:absolute;left:8px;top:68px;width:79px;height:18px;overflow:hidden; /*BorderDivStyle*/" __AddCode="InsideBorderDiv">
<!--BorderDivContents-->
<p class="Wp-Body-P"><label for="text_2"><span class="Body-C">message</span></label></p>
</div>
<!--Postamble-->
<!-- Text Area text_2 -->
<!--Preamble-->
<textarea id="text_2" name="message" rows="2" cols="10" style="position:absolute; left:103px; top:68px; width:100px; height:38px; /*Tag Style*/" __AddCode="here"></textarea>
<!--Postamble-->
<!-- HTML Frame - captcha txt_34 -->
<!--Preamble-->
<div style="position:absolute;left:8px;top:114px;width:69px;height:18px;overflow:hidden; /*BorderDivStyle*/" __AddCode="InsideBorderDiv">
<!--BorderDivContents-->
<p class="Wp-Body-P"><label for="captcha_1"><span class="Body-C">captcha</span></label></p>
</div>
<!--Postamble-->
<!-- Form CAPTCHA captcha_1 -->
<!--Preamble-->
<div style="position:absolute;left:103px;top:114px;width:190px;height:69px; /*MainDivStyle*/" __AddCode="here">
<!--MainDivStart-->
<img src="http://www.serifwebresources.com/util/img_verify.php?gen_word=1&id=captcha_1"><br><input type="text" id="captcha_1" name="captcha_1" size="20" __AddCode="here">
<a title="Listen to audio CAPTCHA" href="http://www.serifwebresources.com/util/audio/audio.php"><img alt="Listen to audio CAPTCHA" style="vertical-align: middle" src="http://www.serifwebresources.com/media/icons/audio-desc.png" border="0"></a><!--MainDivEnd-->
</div>
<!--Postamble-->
<!-- Form Button butn_4 -->
<!--Preamble-->
<input type="submit" style="position:absolute; left:8px; top:191px; width:81px; height:22px; /*Tag Style*/" value="Submit" __AddCode="here">
<!--Postamble-->
</form>
code for PHP (mailform2.php):
<?php
$errors = '';
$myemail = 'myemail';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if( empty($errors))
{
$to = $myemail;
$email_subject = "Website Query: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
$name = $_POST['name'];
In above code if post of name,email and message empty, then it set name = $_POST['name'];
SO $name variable not set.
So code like these
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message'])) {
$errors = 'Please enter all required fields';
}
else
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
}
这篇关于PHP联系表单电子邮件到电子邮件地址,但'名称'字段为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!