1

我为我的网站创建了一个联系表。当我按下发送按钮时,表单会转到应有的感谢页面。当感谢页面显示 url 更改并添加文件夹 /info/ 时。见下文:

http://www.projectrefresh.net/info/thankyou.html

发生这种情况后,所有页面都被破坏,因为 /info/ 已添加且无法识别。

联系表格代码:

<form name="contact" method="POST" action="enquiryForm.php"> 
<p><b>Name</b><br>
</tr>
<tr>
<input type="text" name="Name" size=40>
</tr>
<tr>
<p><b>Your Email</b><br>
</tr>
<tr>
<input type="text" name="email" size=40>
</tr>
<tr>
<p><b>Company</b><br>
</tr>
<tr>
<input type="text" name="Company" size=40>
</tr>
<tr>
<p><b>Subject</b><br>
</tr>
<tr>
<input type="text" name="subject" size=40>
</tr>
<tr>
<p><b>Message</b><br>
</tr>
<tr>
<textarea cols=40 rows=10 name="message"></textarea>
</tr>
<tr>
<p><input type="submit" value=" Send ">
</tr>
</form>
</div>

PHP 脚本:

<?php

$to="info@projectrefresh.net"; // what email address do you wish the email to be sent to?

$subject="Enquiry from website"; // what subject do you want the email to have

$sendto="thankyou.html"; // where do you want the visitor to be sent to afterwards?

//

// This is an UNSUPPORTED web form to email PHP script for usage by DiYhost.co.uk customers

//

$message = "This message has been sent from ".$_SERVER['HTTP_HOST']."\n\n\n";

while(list($var, $val)=each($HTTP_POST_VARS)){        // Get all variables

$message .= "[".$var."]: ".$val."\n\n";                // build the message body           

}

$message .= "\n\nThe person's IP address who sent this email is: ".$_SERVER['REMOTE_ADDR'];

// see http://www.php.net/manual/en/function.mail.php

mail($to, $subject, $message,

    "From: webmaster@".$_SERVER['SERVER_NAME']."\r\n"

  ."Reply-To: webmaster@".$_SERVER['SERVER_NAME']."\r\n"

  ."X-Mailer: PHP/" . phpversion());

// see http://www.php.net/manual/en/function.header.php

header("Location: http://".$_SERVER['HTTP_HOST']

                    .dirname($_SERVER['PHP_SELF'])

                    ."/".$sendto);

?>
4

3 回答 3

1

这是一个非常有用的“解码”站点的链接:http: //validator.w3.org/ - 输入您的页面时出现 = 52 个错误,3 个警告

于 2011-12-05T18:56:42.247 回答
0

链接的问题是,如果它们是这样的......

<a href="index.html">Home</a>

它们是相对于当前页面的。您可以通过使它们相对于网站的根目录来解决您的问题:

<a href="/index.html">Home</a>
于 2011-12-01T17:08:24.040 回答
0

它可能与您的主机提供商的 php 环境有关。可能 dirname($_SERVER['PHP_SELF'] 返回意外的结果。

如何在没有完整路径的情况下替换标题重定向,只是页面:

header("Location: $sendto");

如果您想查看额外的“信息”目录从调试到输出的位置:

echo $_SERVER['HTTP_HOST'];
echo $_SERVER['PHP_SELF'];
echo dirname($_SERVER['PHP_SELF']);

将 header(... 替换为上述 3 行。您可以在此处复制结果。

于 2011-12-01T17:48:02.880 回答