我终于将表单信息发送到我的电子邮箱,但我的表单网页仍然存在问题。当我点击提交按钮时,浏览器不刷新页面,而是转到我的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);
?>
答案 0 :(得分:0)
成功发送电子邮件后使用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;
答案 1 :(得分:0)
您尚未从PHP输出任何内容,因此您只需发送标题即可重定向。
<?php
// ... send email
header('Location: /backToMyForm.html');
?>