[英]How to redirect my forms after submitting info?
我终于将表单信息发送到我的电子邮件,但是表单网页仍然存在问题。 当我按下“提交”按钮时,浏览器不会刷新页面,而是转到我的php.file,其中显示黑页。 我正在尝试将页面重定向回表单网页(不使用Java脚本)。
到目前为止,这是我的代码,包括PHP文件:
<form method="post" action="PHP_Email_Form.php">
<p style="font-family:Arial, Helvetica, sans-serif; color:#FFF; font-size:12px;
font-weight:bold"><label>First Name:
<input type="text" name="First Name" size="30" maxlength="30"
style="margin-left:27px" />
</label></p>
<p style="font-family:Arial, Helvetica, sans-serif; color:#FFF; font-size:12px;
font-weight:bold"><label>Last Name:
<input type="text" name="Last Name" size="30" maxlength="30"
style="margin-left:27px" />
</label></p>
<p style="font-family:Arial, Helvetica, sans-serif; color:#FFF; font-size:12px;
font-weight:bold"><label>Phone Number:
<input type="text" name="Phone Number" size="30" maxlength="10"
style="margin-left:5px" />
</label></p>
<p style="font-family:Arial, Helvetica, sans-serif; color:#FFF; font-size:12px;
font-weight:bold"><label>Email:
<input type="text" name="Email" size="30" maxlength="30"
style="margin-left:59px" />
</label></p>
<p style="margin-top:19px; margin-left:244px;">
<input type="submit" value="submit" />
</p>
</form>
PHP文件:
<?php
$to = 'dew02d@yahoo.com';
$subject = 'test email form';
$message= '';
foreach ($_POST as $key => $value)
{
$message .= $key . ': ' . $value . PHP_EOL;
}
mail($to, $subject, $message);
?>
成功发送电子邮件后,请使用php标头重定向:
<?php
...
...
mail($to, $subject, $message);
header("Location: successmessage.php"); // Redirect browser
/* Make sure that code below does not get executed when we redirect. */
exit;
您尚未从PHP输出任何内容,因此您只需发送标题即可进行重定向。
<?php
// ... send email
header('Location: /backToMyForm.html');
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.