0

我终于将我的表单信息发送到我的电子邮件,但我的表单网页仍然存在问题。当我点击提交按钮时,浏览器不会刷新页面,而是转到我的 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);
 ?>
4

2 回答 2

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;

参考: http: //php.net/manual/en/function.header.php

于 2013-05-04T23:57:56.103 回答
0

你还没有从你的 PHP 中输​​出任何东西,所以你可以发送一个标头来重定向。

<?php

// ... send email

header('Location: /backToMyForm.html');

?>
于 2013-05-04T23:58:49.490 回答