0

我有一个简单的联系表格,客户将在其中放置他们的推荐信,尽管在提交表格后它会将我带到流程页面,这很好,因为执行了感谢页面。但在提交后,它只会将我带到 posses 页面,而不是感谢页面。我找不到问题,可以向你们寻求帮助

表格:

 <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 = 'marketing@loanro.co.za'; // 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])+@[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>
4

3 回答 3

1

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

而且最好放在ob_start();任何输出ob_end_clean();之前和重定向之前。

干杯

于 2013-10-10T08:34:06.623 回答
1

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

你的header()电话好像打不通。如果您在此调用之前有任何类型的输出,通常就是这种情况。这可以是 php 脚本开始标记之前的任何空格(空格、换行符等),<?甚至可以是像UTF-BOM这样的不可见字符。如果您使用像 Notepad++ 这样的编辑器,您可以检查文件是否以 UTF 编码保存并确保它没有 BOM。

于 2013-10-10T08:21:19.303 回答
0

你的代码看起来不错。由于 2 个原因,Location 标头可能会失败:

  1. 您的脚本在发送标头之前做了一些输出(可能是一个错误,或者只是一个看不见的标志<?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 = 'marketing@loanro.co.za'; // 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])+@[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>";
  }
?>

如果这仍然不起作用,请停止使用 Location 并执行以下操作:

readfile($returnpage);

反而。

顺便说一句,您的代码示例看起来不像完整的 html 页面,它们至少应该被包围

<html>
  <body>
  // Your content
  </body>
</html>
于 2013-10-10T09:12:26.190 回答