PHP表单重定向到PHP文件本身
我试图让一个联系人表单工作,我被重定向到PHP文件本身,我不知道为什么。我对PHP相当陌生,我不完全确定自己做错了什么。我希望被指向正确的方向。代码如下 谢谢 HTML:PHP表单重定向到PHP文件本身,php,html,Php,Html,我试图让一个联系人表单工作,我被重定向到PHP文件本身,我不知道为什么。我对PHP相当陌生,我不完全确定自己做错了什么。我希望被指向正确的方向。代码如下 谢谢 HTML: 请填写所有字段* PHP: 这一行告诉表单将数据发送到哪个PHP文件: <form id="contact_us" enctype="text/plain" method="post" action="form.php"> 事实上,这很好。可以在包含表单的同一PHP文件中处理表单。只需将PHP表单处理
请填写所有字段*
PHP:
这一行告诉表单将数据发送到哪个PHP文件:
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
事实上,这很好。可以在包含表单的同一PHP文件中处理表单。只需将PHP表单处理放在顶部:
<?php
if (isset($_POST['Email_Address'] && $_POST['Email_Address'] != ''){
$to = 'zack@zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
EMAIL;
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>
只需删除enctype=“text/plain”
即可,否则您的代码在HTML中是正确的,并尝试回显反馈变量另一种方法是将所有代码写入HTML之上,如下所示:
<?php
if (isset($_POST['Email_Address'] && !empty['Email_Address']){
$to = 'zack@zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>
删除enctype=“text/plain”
,此$header=$subject代码>将失败。阅读手册@Fred ii-仍然重定向到浏览器中的form.php,一个空白页面,尝试回应$feedback;$feedback之后='Email sent!';由于form.php
不回显任何内容,因此预期结果是空白页面。您应该通过header
函数重定向到另一个地方,或者在脚本末尾回显某个内容。。。重定向回当前php文件或处理当前php文件中的请求。heredoc结束标识符前的空格不应存在。理论上,这将抛出一个解析错误。埃雷多克:
action="form.php"
<?php
if (isset($_POST['Email_Address'] && $_POST['Email_Address'] != ''){
$to = 'zack@zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
EMAIL;
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>
<?php
if (isset($_POST['Email_Address'] && !empty['Email_Address']){
$to = 'zack@zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>