我的 php 表单在 bluehost 服务器上生成错误

发布于 2024-12-18 19:18:53 字数 2497 浏览 3 评论 0原文

我为我的网站创建了联系表格。当我按下发送按钮时,表单会按其应有的方式进入感谢页面。当感谢页面显示网址更改并添加文件夹 /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="[email protected]"; // 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);

?>

I have created a contact form for my website. When I press the send button the form goes to a thank you page as it should. When the thank you page displays the url changes and a folder /info/ is added. see below:

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

After this happens all pages are broken as /info/ has been added and is not recognized.

Contact form code:

<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 Script:

<?php

$to="[email protected]"; // 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);

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怂人 2024-12-25 19:18:53

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

Here is a link to a very helpful "de-coding" site: http://validator.w3.org/ - entering your page came up with = 52 Errors, 3 warning(s)

红墙和绿瓦 2024-12-25 19:18:53

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

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

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

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

The problem with the links is that if they are like this...

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

They are relative to the current page. You could solve your issue by making them relative to the root of the website:

<a href="/index.html">Home</a>
墟烟 2024-12-25 19:18:53

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

如何替换没有完整路径的标头重定向,仅替换页面:

header("Location: $sendto");

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

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

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

It could have something to do with your host provider's php environment.
Probably the dirname($_SERVER['PHP_SELF'] returns the unexpected result.

How about replacing the header redirect without the full path, just the page:

header("Location: $sendto");

If you want to see where the extra "info" dir comes from debug to output:

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

Replace header(... with the above 3 lines. You could copy the result here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文