联系表单PHP重定向不工作 [英] contact form PHP redirect is not working

查看:139
本文介绍了联系表单PHP重定向不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

在我的联系表单上提交邮件后,我想尝试重定向到我的主页,表单发送电子邮件,但我收到以下消息: code> Array

[name] => Abdo
[company] =>MediabyrånA& B
[email] => a.el- madhoun@hotmail.com
[content] => Hejsan
[contact_to] => info@web.se

已发送的邮件头(
/ customers / 4 / 5 / a / webelite.se / httpd.www / kontakt.php:3)在
/customers/4/5/a/webelite.se/httpd.www/kontakt.php第39行


我的联系表单;

 < form action =kontakt.phpmethod =post> 
< p>< input type =textrequired =requiredid =namename =nameclass =text_inputsize =22/>
< label for =name> Namn *< / label>< / p> id =companyname =companyclass =text_inputsize =22/>
< label for =company>Företag*< / label>< / p>

< p>< input type =emailrequired =requiredid =emailname =emailclass =text_inputsize =22/>
< label for =email> Epost *< / label>< / p> name =contentclass =textareacols =30rows =5>< / textarea>< / p为H.

< p>< button type =submitclass =button white>< span> Skicka< / span>< / button>< / p>
< input type =hiddenvalue =info@web.sename =contact_to/>
< / form>

这是我的PHP:

 <?php 

echo $ name = $ _POST ['name'];
echo $ company = $ _POST ['company'];
echo $ email = $ _POST ['email'];
echo $ content = $ _POST ['content'];

$ mail_to ='info@webelite.se';
$ subject ='Lilla form'。$ name;

$ body_message ='From:'。 $名称。 \\\
;
$ body_message。='company:'。 $公司。 \\\
;
$ body_message。='E-mail:'。 $ email。\\\
;
$ body_message。='Message:'。 $内容;

$ headers ='From:'。 $ mail_name。 \r\\\
;
$ headers。='Reply-To:'。 $ email。\r\\\
;

$ success = mail($ mail_to,$ subject,$ body_message,$ headers);

echo< pre>;
print_r($ _ POST);

header('Location:mydomain');

?>

我还尝试使用if

 ($ success){
print< meta http-equiv = \refresh\content = \0; URL = YOUR_PAGE_HERE.html\ ;

这样工作,但是在点击提交和被重定向之前,我有一个丑陋的一秒钟的闪光。 >

所有帮助都是可以的。



谢谢



删除所有的 echo 'es和 print_r 的,你应该没事。



编辑: strong>



另外作为@jhonraymos提到,请务必正确使用 header()。也许你改变了这个,以隐藏你被重定向到的实际页面。添加具有正确路径定义的本地文件,或者如果重定向到另一个域,则需要定义完整的URL。如有疑问,请参阅统一资源定位器



另一个编辑



我看到你更新了你的问题。停止尝试印度魔法,如

  if($ success){
print< meta http-equiv = \refresh\content = \0; URL = YOUR_PAGE_HERE.html\>;

只需接受 之前< c $ c> headers(),你的灵魂永远是安全的。这不是混合http-meta的地方,PHP可以做到这一点很好。



这可能听起来是一个限制,但相信我,它不是。这是一个祝福。


I im trying to redirect to my homepage after submitting a message on my contact form, the form sends the email but I get this message:

Array
(
    [name] => Abdo
    [company] => Mediabyrån A&B
    [email] => a.el-madhoun@hotmail.com
    [content] => Hejsan
    [contact_to] => info@web.se
)

Warning: Cannot modify header information - headers already sent by (output started at /customers/4/5/a/webelite.se/httpd.www/kontakt.php:3) in /customers/4/5/a/webelite.se/httpd.www/kontakt.php on line 39

My contact form;

<form action="kontakt.php" method="post">
<p><input type="text" required="required" id="name" name="name" class="text_input" size="22"  />
<label for="name">Namn *</label></p>

<p><input type="text" required="required" id="company" name="company" class="text_input" size="22"  />
<label for="company">Företag *</label></p>

<p><input type="email" required="required" id="email" name="email" class="text_input"  size="22"  />
<label for="email">Epost *</label></p>

<p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>

<p><button type="submit" class="button white"><span>Skicka</span></button></p>
<input type="hidden" value="info@web.se" name="contact_to"/>
</form>

and this is my PHP:

<?php

echo $name = $_POST['name'];
echo $company = $_POST['company'];
echo $email =  $_POST['email'];
echo $content = $_POST['content'];

$mail_to = 'info@webelite.se';
$subject = 'Lilla form'.$name;

$body_message = 'From: '. $name . "\n"; 
$body_message .= 'company: '. $company . "\n";
$body_message .= 'E-mail: '. $email ."\n";
$body_message .= 'Message: '. $content;

$headers = 'From: '. $mail_name . "\r\n";
$headers .= 'Reply-To: '. $email ."\r\n";

$success = mail($mail_to, $subject, $body_message, $headers);

echo "<pre>";
print_r($_POST);

header('Location:mydomain');

?>

I also tried using if

($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=YOUR_PAGE_HERE.html\">"; 

This worked but I got a ugly half a second flash between hitting submit and being redirected.

All help is appriciated.

Thank you

解决方案

You can't output anything to the screen before redirecting.

Remove all your echo'es and print_r's and you should be fine.

EDIT:

Also as @jhonraymos mentioned, be sure to use header() properly. Maybe you changed this to hide your actual page you're redirecting to. Either add a local file with correct path definitions or if redirecting to an other domain, you need to define the full url. See Uniform resource locator if in doubt.

Another EDIT:

I see you updated your question. Stop trying indian magic, such as

if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=YOUR_PAGE_HERE.html\">";

Just accept the fact not to output ANYTHING to the screen before headers() and your soul is safe forever. This is not the place to mix http-meta in. PHP can do this just fine.

This might sound as a limitation first, but believe me, it isn't. It's a blessing.

这篇关于联系表单PHP重定向不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆