2013-10-10 59 views
0

我有一个简单的联系表单,客户将把他们的推荐,尽管提交表单时,我将它带到流程页面,这是很好的原因,谢谢你的页面实现了。但提交后,它只是带我到页面的页面,而不是感谢页面。我无法找到问题,可以使用一些帮助,从你们窗体只输出错误

形式:

<form action="includes/mail.php" method="post"> 
<table background="images/sequestrationreferral.jpg" height="408px" width="740px"> 
<tr> 
<td width="80px" height="50px"><label>Name:</label></td> 
<td><input class="input" type="text" name="name" width="225px" /></td> 
</tr> 
<tr> 
<td width="80px" height="50px"><label>Email Address:</label></td> 
<td><input class="input" type="text" name="email" width="225px" /></td> 
</tr> 
<tr> 
<td width="80px" height="120px"><label>Referals:</label></td> 
<td><textarea class="input" name="referals" cols="35" rows="5"></textarea><br /><br />Please use one per row?</td> 

</tr> 
<tr> 
<td></td> 
<td><input type="submit" name="submit" value="Send referals" class="btn" /></td> 
</table> 
</form> 

进程页:

<? 
/* Edit these preferences to suit your needs */ 

    $mailto = '[email protected]'; // insert the email address you want the form sent to 
    $returnpage = '../thanks.php'; // insert the name of the page/location you want the user to be returned to 
    $sitename = '[Loanro]'; // insert the site name here, it will appear in the subject of your email 

/* Do not edit below this line unless you know what you're doing */ 

    $name = $_POST['name']; 
    $email = $_POST['email'] ; 
    $referals = stripslashes($_POST['referals']); 

    if (!$name) { 
     print("<strong>Error:</strong> Please provide your name.<br/><br/><a href='javascript:history.go(-1)'>Back</a>"); 
     exit; 
    } 
    if (!$email) { 
     print("<strong>Error:</strong> Please provide an email address.<br/><br/><a href='javascript:history.go(-1)'>Back</a>"); 
     exit; 
    } 
    if (!$referals) { 
     print("<strong>Error:</strong> Please provide your enquiry details.<br/><br/><a href='javascript:history.go(-1)'>Back</a>"); 
     exit; 
    } 
    if (!eregi("^[a-z0-9]+([-_\.]?[a-z0-9])[email protected][a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)){ 
    print("<strong>Error:</strong> this email address is not in a valid format.<br/><br/><a href='javascript:history.go(-1)'>Back</a>"); 
     exit; 
    } 

    $message = "\n$name submitted the following message:\n\n$enquiry\n\nTheir contact details are as follows:\n\nName: $name\nEmail Address: $email\n\n"; 

    mail($mailto, "$sitename Referal from $name", $message, "From: $email"); 
    header("Location: " . $returnpage); 
?> 

而且谢谢页:

<article class="art-post art-article"> 


       <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout layout-item-0"> 
    <div class="art-content-layout-row"> 

    </div> 
</div> 
<div class="art-content-layout-wrapper layout-item-4"> 
<div class="art-content-layout"> 
    <div class="art-content-layout-row"> 
    <div class="art-layout-cell layout-item-5" style="width: 75%" > 
<p>Thank you for contacting up, we will get back to you as soon as possible.</p> 


    </div> 
    </div> 
</div> 
</div> 
</div> 



</article> 
+0

尝试包围“ob_end_clean();”之前“标题()” – tinybyte

+0

我认为这个问题是因为在进程页面有问题,你在进程页面中得到了什么错误? – ncm

+0

如果是输出错误,似乎没有显示谢谢页面......但是你不应该在头部之前显示任何东西 – Brewal

回答

0

您的代码看起来没问题。 Location头可能会失败,因为2个原因:

  1. 脚本yust做befor发送的报头部分的输出(可能是一个错误,或者befor你<?php
  2. Location头应该是用户简单的一个看不见的标志与绝对的URL,也许是你的相对路径问题

你可以取代你的位置与头:

$returnurl = "http://".$_SERVER["SERVER_NAME"] 
      . ($_SERVER["SERVER_PORT"]!=80?":".$_SERVER["SERVER_PORT"]:"") 
      . dirname($_SERVER["PHP_SELF"]) . "/" 
      . $returnpage; 
header("Location: " . $returnurl); 

而为了让成功和输入错误之间的差别更好,你不需经过你的脚本改为:

<? 
/* Edit these preferences to suit your needs */ 

    $mailto = '[email protected]'; // insert the email address you want the form sent to 
    $returnpage = '../thanks.php'; // insert the name of the page/location you want the user to be returned to 
    $sitename = '[Loanro]'; // insert the site name here, it will appear in the subject of your email 

/* Do not edit below this line unless you know what you're doing */ 

    $name = $_POST['name']; 
    $email = $_POST['email'] ; 
    $referals = stripslashes($_POST['referals']); 

    $errors = array(); 
    if (!$name)  $errors[] = "Please provide your name."; 
    if (!$email)  $errors[] = "Please provide an email address."; 
    if (!$referals) $errors[] = "Please provide your enquiry details."; 
    if (!eregi("^[a-z0-9]+([-_\.]?[a-z0-9])[email protected][a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)) { 
    $errors[] = "this email address is not in a valid format."; 
    } 

    if(count($errors) == 0) 
    { 
    $message = "\n$name submitted the following message:\n\n$enquiry\n\nTheir contact details are as follows:\n\nName: $name\nEmail Address: $email\n\n"; 

    mail($mailto, "$sitename Referal from $name", $message, "From: $email"); 
    $returnurl = "http://".$_SERVER["SERVER_NAME"] 
       . ($_SERVER["SERVER_PORT"]!=80?":".$_SERVER["SERVER_PORT"]:"") 
       . dirname($_SERVER["PHP_SELF"]) . "/" 
       . $returnpage; 
    header("Location: " . $returnurl); 
    } 
    else 
    { 
    echo "<strong>Errors:</strong>"; 
    echo "<ul><li>".implode("</li>\n<li>",$errors)."</li></ul>"; 
    echo "<a href='javascript:history.go(-1)'>Back</a>"; 
    } 
?> 

如果这仍然不起作用,停止使用地点的待办事项:

readfile($returnpage); 

代替。

顺便说一下,你的代码示例不`吨看起来像全HTML网页,他们应该至少有

<html> 
    <body> 
    // Your content 
    </body> 
</html> 
1

如果您的网络服务器配置为显示警告(或者您可以启用它们进行开发),请提供它们。

看来您的header()调用不起作用。通常情况下,如果在此调用之前您有任何类型的输出。这可以是PHP脚本的开始<?标记之前的任何空格(空格,换行符等),或者它甚至可以是不可见的字符,如UTF-BOM。如果您使用Notepad ++之类的编辑器,则可以检查文件是否以UTF编码保存并确保其不含BOM。

+0

+1您指出会导致此类问题的很好的一点。 – ncm

1

php(即<?,?><?= 'something' ?>)标签有时会产生问题。我总是把完整的PHP标签(<?php ?><?php echo 'something' ?>

而且还最好是把ob_start();任何输出前,ob_end_clean();重定向之前。

欢呼声