【发布时间】:2011-09-23 19:55:51
【问题描述】:
我创建了一个联系表单,它使用我的 php 脚本通过电子邮件发送表单参数:
//File email.php
<?php
include('variables.php');
$to = "info@timeshare.org.uk";
$subject = "Quote From Website";
$name = $_POST["name"];
$email = $_POST["email"];
$number = $_POST["number"];
$resort = $_POST["resort"];
$headers = "From: ".$to."\r\n";
$message = "Name: ".$name."\r\n".
"Email: ".$email."\r\n".
"Number: ".$number."\r\n".
"Resort Name:".$resort."\r\n";
if (mail($to,$subject,$message,$headers)){
$replyHeader = "Thank You!";
$replyMessage = "Thank you for using our quick contact form. We will get back to you as soon as possible.";
}else{
$replyHeader = "Oops!";
$replyMessage = "An Error Occured whilst trying to send the form. Please try again later";
}
header( 'Location: http://localhost/TimeShare/formReturn.php' ) ;
?>
在提交表单时指向此代码。
现在,如果邮件功能成功,我希望表单重定向到 formReturn.php,但是我希望特定 div 中的内容显示 $replyHeader 和 $replyMessage。
因此,一旦表单发布,它会重定向到显示成功消息或错误消息的页面。
现在在我的 formReturn.php 页面上,我尝试包含变量,如下所示:
//File: formReturn.php
<body>
//Header code...
//sidebar code...
<div>
<?php include('php/email.php'); ?>
<h1> <?php echo $replyHeader; ?> </h1>
<p> <?php echo $replyMessage ?> </p>
</div>
//Footer code...
</body>
此代码的问题是,因为我包含 email.php 文件,我最终会出现重定向循环。哪个不好!
那么我如何根据 mail() 函数的成功或失败将变量 $replyHeader 和 $replyMessage 放到该特定位置的页面上
【问题讨论】:
标签: php