我有一个简单的表格:
<form action="send_form_email.php" method="post" enctype="text/plain">
<input type="text" name="first_name" placeholder="NAME:" size="100" class="grey-bg"/>
<input type="text" name="last_name" placeholder="E-MAIL:" size="100" class="grey-bg"/>
<br />
<br />
<textarea type="text" name="message" rows="20" cols="201" placeholder="MESSAGE:" size="162"></textarea>
<br />
<div>
<input id="contact-send-btn" type="submit" value="Send">
</div>
</form>
这是php文件:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "xxxxxxxx";
$email_subject = "Hello";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['message']) ||
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
$message = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Message: ".clean_string($email_from)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
然而,当我点击按钮时,它只是在浏览器中打开php文件,我的收件箱中没有收到任何内容?我想要的只是收到表格中的详细信息?
答案 0 :(得分:1)
你有几个问题。
enctype="text/plain"
PHP不支持纯文本编码表单数据。 删除该属性(并使用默认编码类型)。
另见the spec:
使用text / plain格式的有效负载是人类可读的。它们无法通过计算机可靠地解释,因为格式不明确(例如,无法区分值中的文字换行符和值末尾的换行符。)
你说if(isset($_POST['email'])) {
...但您没有name="email"
的任何字段。测试你实际存在的字段是否存在*
这句话有点含糊不清:
它只是在浏览器中打开php文件
如果您的浏览器显示PHP源代码,请参阅此问题:PHP code is not being executed (I can see it on source code of page)
placeholder="NAME:"
The HTML5 placeholder attribute is not a substitute for the label element
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
这无法匹配许多完全有效的电子邮件地址(例如+
之前的部分@
或.museum
顶级域名中的 var tableData= objHiveContext.hql("select * from intervalmeterdemandbymonth c")
println(tableData) //Line1
var rowData = tableData.collect()
println(rowData)`
。
答案 1 :(得分:0)
您没有添加name
属性来提交按钮。
更改
<input id="contact-send-btn" type="submit" value="Send">
要:
<input id="contact-send-btn" type="submit" value="Send" name="email"/>
发布表单时,仅发布名称为get
的元素。
在您的情况下,提交按钮没有名称属性,因此,它没有被发布。
因此,它没有进入if
。
答案 2 :(得分:0)
看起来你没有apache,安装了php,这就是你看到.php文件内容的原因。如果您使用的是Windows,请安装XAMPP Install LAMP Stack 。希望这有帮助