PHP 联系表 - 发送后希望留在我的网站上
我正在创建一个 PHP 联系表单,我所遇到的只是一个小问题,即我的 php 脚本在发送电子邮件时会调用一个新的“谢谢”页面.因此,带有联系表单的实际网站消失了,但我不希望这种情况发生。
如果点击发送按钮,我想留在我的网站上,显示一个空的联系人表格,也许在联系表格下方只有 1 行,说“谢谢......”。
我怎样才能做到这一点?是有没有任何代码片段可以向我解释我必须包含在 html 和 php 文件中的内容?希望它会...下面是我的 php 现在的结束方式。
// send Email
if (@mail( $empfaenger, htmlspecialchars( $betreff ), $mailbody, $mailheader ))
{
// if email was successfully send
echo 'Thank you for your Email. We will get in touch with you very soon.';
}
编辑
@FreekOne
目前,我正在对您的代码进行轻微修改,因为我想让谢谢和/或错误面板滑出并让文本淡入。该脚本正在接受我的代码(因为它仍在工作),但实际上我不能看到文本实际上淡入。我见过滑动面板的文本淡入的示例。所以这似乎是我所做的一种错误的编码。
如果需要,请在此处查看代码:
http://jsbin.com/ohuya3
也许你可以给我指出正确的方向。当然,我们将不胜感激这里所有人的帮助。
I am in the process of creating a PHP contact form and all I have is that little problem, with the php script I have, that when the email was send out a new "Thank you" page is called.So the actual site with the contact form disappears BUT I DON`T WANT THAT HAPPEN.
If the send button is hit I want to stay on my site, showing an empty contact form and maybe below the contact form just 1 line, saying "Thank you.....".
How can I make that happen? Is there any code snippet out there that can explain to me what I have to include to my html and to my php file? Hopefully it will...Below is how my php ends right now.
// send Email
if (@mail( $empfaenger, htmlspecialchars( $betreff ), $mailbody, $mailheader ))
{
// if email was successfully send
echo 'Thank you for your Email. We will get in touch with you very soon.';
}
EDIT
@FreekOne
Currently I am using your code with a slight modification because I wanted to make the thank you and or error panel make slide out and have the text fade in. The script is accepting my code (because it is still working) but actually I can not see that the text actually fades in. I have seen samples of sliding panels with fading in text. So it seems to be a wrong kind of coding that I did.
Please view the code here if you want:
http://jsbin.com/ohuya3
Maybe you can point me to the right direction. Of course, help would be appreciated from all of you guys here around.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置表单以将数据发送到同一页面,并让您的脚本侦听提交。类似于:
contact.php
UPDATE
考虑到提供的额外信息,我个人会通过 AJAX 使用 jQuery 来完成此操作。首先,设置表单和结果容器:
HTML
然后设置 php 脚本来处理提交的数据并输出响应。
PHP (contact.php)
最后,jQuery 脚本将在不离开页面的情况下提交表单,并将结果插入结果容器中(具有漂亮且简单的淡入淡出效果)。
jQuery
希望这有帮助!
Set the form to send the data to the same page, and have your script listen for a submit. Something like:
contact.php
UPDATE
Considering the provided extra info, I would personally do it with jQuery, through AJAX. First, setup your form and the container for the result:
HTML
Then setup the php script which handles the submitted data and outputs the response.
PHP (contact.php)
And finally, the jQuery script which will submit your form without leaving the page and insert the result in your result container (with a nice and simple fade in effect).
jQuery
Hope this helps !
下面所有这些答案都是错误的。它有时会让您收到重复的垃圾邮件,并使客户感到困惑。
虽然解决方案有点棘手
首先你必须学习黄金法则:
处理 POST 请求后,您的代码应使用 GET 方法重定向浏览器。没有例外。
因此,首先要像这样,
无论如何你都应该这样做。
接下来,如果你仍然想显示这个无用的消息,你有几种方法可以做到。
例如,使用 GET 参数
All these answers below are wrong. It will make you occasionally spammed with doubled messages and confuse customers.
Though the solution is kinda tricky
First of all you have to learn the Golden rule:
After processing POST request, your code should redirect a browser using GET method. No exceptions.
Thus, first make it like this
You ought to do it anyway.
Next, if you still want to show this useless message, you have several ways to do it.
for example, to use a GET parameter