[英]PHP Contact Form sending blank emails, text input not showing up in email
I am having some trouble with my php email form. 我的php电子邮件表单遇到了一些麻烦。 I asked this question earlier but, but realized it was poorly worded so I deleted that and tried again.
我早些时候问了这个问题,但是意识到它的措词不佳,所以我删除了该问题并再次尝试。 I am new to this forum, I'm still getting used to how to post.
我是这个论坛的新手,我仍然习惯于如何发布。
My html contact form is going through but sending blank emails. 我的html联系人表单正在处理,但是发送空白电子邮件。
Here us my HTML form: 这是我们的HTML表单:
<form id="contact_form" class="cf" name="contact_form" action="mailscript.php" method="POST">
<div id="left_form_container">
<div class="half_left_cf">
<input type="text" name="name" id="input_name" placeholder="Name">
<input type="email" name="email" id="input_email" placeholder="Email address">
<input type="text" name="subject" id="input_subject" placeholder="Subject">
</div>
</div>
<div id="right_form_container">
<div class="half_right_cf">
<textarea name="message" id="input_message" type="text" placeholder="Message"></textarea>
<div id="submit_container">
<input type="submit" name="submit" value="Submit" id="input_submit">
</div>
</div>
</div>
</form>
And here is my php code: 这是我的PHP代码:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "mail@thomasjeffery.design";
$body = "From: ".$name."\n E-Mail: ".$email."\n Message:\n" .$message;
if(mail ($to, $subject, $body)){
echo "<script>
alert('Thank you for sending your message!');
window.location.href='index.php';
</script>";}
else {echo "Mail was not sent!";}
?>
The email works (it sends an email), and the echo displays a "thank you" and returns the user to the main page, but the form information from the contact form is not being sent through.. 电子邮件有效(发送电子邮件),并且回显显示“谢谢”并将用户返回主页,但联系表单中的表单信息未通过发送。
Instead, the email just reads: "From: E-mail: Message:". 而是,电子邮件仅显示为:“发件人:电子邮件:消息:”。
Can anyone tell me why it is not including the input fields from my html form? 谁能告诉我为什么它不包括我的html表单中的输入字段? It seems very simple but I cannot seem to figure it out.
看起来很简单,但我似乎无法弄清楚。
You may try do some debugging with your request like: 您可以尝试对请求进行一些调试,例如:
echo "<pre>";
print_r($_REQUEST);
print_r($_GET);
print_r($_POST);
echo "</pre>";
Also, you gotta make sure that your form method attribute either POST or GET method. 另外,您必须确保您的form方法属性为POST或GET方法。
From the looks of your code it seems you forgot to add a form opening tag. 从代码的外观看,您似乎忘记了添加表单开始标签。 "
<form>
" “
<form>
”
eg. 例如。
<form method="post" action="thepagetosubmit.php">
possible fullcode. 可能的完整代码。
<form method="post" action="thepagetosubmit.php">
<div id="left_form_container">
<div class="half_left_cf">
<input type="text" name="name" id="input_name" placeholder="Name">
<input type="email" name="email" id="input_email" placeholder="Email address">
<input type="text" name="subject" id="input_subject" placeholder="Subject">
</div>
</div>
<div id="right_form_container">
<div class="half_right_cf">
<textarea name="message" id="input_message" type="text" placeholder="Message"></textarea>
<div id="submit_container">
<input type="submit" name="submit" value="Submit" id="input_submit">
</div>
</div>
</div>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.