我是Php的新手,所以请保持温柔。
我写了一个网站,我添加了订阅时事通讯部分。用户在按提交前添加其姓名和电子邮件地址。我收到的电子邮件大部分都在工作,但表格并没有让我回到网站的主页面。谁能指出我哪里出错了?
提前致谢
网站上的代码是:
<form name="frmcontact" id="frmcontact" action="php/contact.php" method="post">
<input id="name" name="name" type="text" value="Name"
onblur="this.value=(this.value=='') ? 'Name' : this.value;" onfocus="this.value=(this.value=='Name') ? '' : this.value;" />
<input id="email" name="email" type="text" value="Email"
onblur="this.value=(this.value=='') ? 'Email' : this.value;" onfocus="this.value=(this.value=='Email') ? '' : this.value;" />
<input name="submit" id="send" type="submit" value="Message" />
</form>
The code in contact.php is:
<?php session_start();
if(!$_POST) exit;
$address = 'email@emailaddress.com';
$email_subject ="Add me to the mailing list";
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = "Please add me to the mailing list ";
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$e_subject = 'You\'ve been contacted by ' . $name . '.';
$msg = "You have been contacted by $name with regards to $subject.\r\n\n";
$msg .= "$message\r\n\n";
$msg .= "You can contact $name via email, $email.\r\n\n";
$msg .= "-------------------------------------------------------------------------------------------\r\n";
if(@mail($address, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{echo "<p class='ajax_success'>Thanks for Contact Us.</p>"; }
else
{echo "<p class='ajax_failure'>Sorry, Try again Later.</p>"; }
header('Location:http://www.websiteaddress/homepage.html');
?>
答案 0 :(得分:0)
在header
之后exit
使用header
之前移除所有输出,并考虑在下方标注空格
v
header('Location: http://www.websiteaddress/homepage.html');
exit;
答案 1 :(得分:0)
使用正确的目录路径
if(isset($_POST['submit'])){
$address = 'email@emailaddress.com';
$email_subject ="Add me to the mailing list";
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = "Please add me to the mailing list ";
if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }
$e_subject = 'You\'ve been contacted by ' . $name . '.';
$msg = "You have been contacted by $name with regards to $subject.\r\n\n";
$msg .= "$message\r\n\n";
$msg .= "You can contact $name via email, $email.\r\n\n";
$msg .= "-------------------------------------------------------------------------------------------\r\n";
if(@mail($address, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
{echo "<p class='ajax_success'>Thanks for Contact Us.</p>"; }
else
{echo "<p class='ajax_failure'>Sorry, Try again Later.</p>"; }
header('Location: homepage.html');
}
答案 2 :(得分:0)
在使用标题()
之前,你无法输出任何内容HTTP-Headers应该在服务器的任何输出之前发送。如果您之前有输出,服务器将输出一个警告,例如“已经发送了标题”&#39;
<?php
ob_start();
echo "redirecting now ....";
header('Location: http://www.websiteaddress/homepage.html');
exit();
ob_end_flush();
?>