[英]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.