dongsuyou6938 2015-05-23 14:27
浏览 28
已采纳

无法在PHP 5.5.9中获取代码[关闭]

This code works fine in PHP 5.3, but I can't figure out what to do to make it working in PHP 5.5.9 on a LAMP server. I have tried searching around, but haven't found any solution. Any ideas of to fix it?

So; the users sees the from correctly, without the fact it always says the mail is sent, even befor they hit the submit button. Second, the mail that it should send in the end, will not be sent, nothing happens.

<body> 

<?php
//Variabals and validastions
$firstnameErr = $secondnameErr = $surenameErr = $emailErr = $dateErr = $gateErr = $pnumErr = "";
$firstname = $secondname = $surename = $email = $date = $gate = $pnum = "";
$Err = "1";
$date = date("d/m/Y");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   if (empty($_POST["firstname"])) {
     $firstnameErr = "Firstname is needed";
     $Err = "2";
   } else {
     $firstname = test_input($_POST["firstname"]);
     if (!preg_match("/^[a-åA-Å ]*$/",$firstname)) {
       $firstnameErr = "Only letter and spaces";
       $Err = "2";
     }
   }
   if (empty($_POST["secondname"])) {
     $secondname = " ";
    } else {
     $secondname = test_input($_POST["secondname"]);
     if (!preg_match("/^[a-åA-Å ]*$/",$secondname)) {
       $secondnameErr = "Only letter and spaces";
       $Err = "2";     
     }
   }

   if (empty($_POST["surename"])) {
     $surenameErr = "Surename is needed";
     $Err = "2";
   } else {
     $surename = test_input($_POST["surename"]);
     if (!preg_match("/^[a-åA-Å ]*$/",$surename)) {
       $surenameErr = "Only letter and spaces";
       $Err = "2";
     }
   }

   if (empty($_POST["email"])) {
     $emailErr = "E-postadresse is needed";
     $Err = "2";
   } else {
     $email = test_input($_POST["email"]);
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
       $emailErr = "Not valid email"; 
       $Err = "2";
     }
   }
    if (empty ($_POST["date"])) {
     $dateErr = "Fødselsdate is needed";
     $Err = "2";
    } else {
     $date = test_input ($_POST["date"]);
    }

    if (empty($_POST["gate"])) {
     $gateErr = "Gateadresse is needed";
     $Err = "2";
   } else {
     $gate = test_input($_POST["gate"]);
     if (!preg_match("/^[a-åA-Å0-9. ]*$/",$gate)) {
       $gateErr = "Invalid characters, only letters, numbers and space"; 
       $Err = "2";
     }
   }

   if (empty($_POST["pnum"])) {
     $pnumErr = "Post number is needed";
     $Err = "2";
   } else {
     $pnum = test_input($_POST["pnum"]);
     if (!preg_match("/^\d{4}$/",$pnum)) {
       $pnumErr = "Invalid post number"; 
       $Err = "2";
     }
   }
   if ($Err == "1") {
     $Err = "";
   }
}
function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}

?>

<!--Form-->
<div>
<div>
<img src="https://wiki.piratpartiet.no/images/1/18/Ole.png" alt="uPir logo" width="400px">
<h1 style="text-align:center">Application form</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
<table style="width:100%">
    <tr>
    <td>
    Firstname: <br>
    <input name="firstname" type="text" value="<?php echo $firstname;?>">
    <span class="error">* <br>
    <?php echo $firstnameErr;?></span>
    <br><br>
    </td>
    <td>
    Secondname:<br>
    <input name="secondname" type="text" value="<?php echo $secondname;?>">
    <span class="error"><br>
    <?php echo $secondnameErr;?></span>
    <br><br>
    </td>
    </tr>
    <tr>
    <td>
    Surename:<br>
    <input name="surename" type="text" value="<?php echo $surename;?>">
    <span class="error">* <br>
    <?php echo $surenameErr;?></span>
    <br><br>
    </td>
    </tr>
    <tr>
    <td>
    E-mail:<br> 
    <input name="email" type="mail" value="<?php echo $email;?>">
    <span class="error">* <br>
    <?php echo $emailErr;?></span>
    <br><br>
    </td>
    <td>
    Brithdate (dd.mm.yyyy):<br>
    <input name="date" type="date" min="1900-01-01" max="2015-12-31" value="<?php echo $date;?>">
    <span class="error">* <br>
    <?php echo $dateErr;?></span>
    <br><br>
    </td>
    </tr>
    <tr>
    <td>
    Adress:<br>
    <input name="gate" type="text" value="<?php echo $gate;?>">
    <span class="error">* <br>
    <?php echo $gateErr;?></span>
    <br><br>
    </td>
    <td>
    Post number:<br>
    <input name="pnum" type="number" value="<?php echo $pnum;?>">
    <span class="error">* <br>
    <?php echo $pnumErr;?></span>
    <br><br>
    </td>
    </tr>
</table>
    <?php
//Controll and mailsender
if (empty($Err["Err"])) {
    $to = 'email@adress.com';
    $subject = 'subject';
    $message = "$firstname $secondname $surename ønsker å bli medlem.
E-post: $email
Fødselsdate: $date
Gateadresse: $gate
Postnummer: $pnum

Sendt: $date
--massages info here--";
    mail($to, $subject, $message);
    echo '<p class="sucsess">Messages sent</p>';
}
?>
    <p style="text-align:center"><input type="submit" name="sumbit" value="Register" id="submit"></p>
</div>
</form>
</div>

</body>

The issue is that on 5.5.9 it dosn't send the info mail (to me) and the user gets up the info that the mail is sent before they have hit the sumbit button, and even if it's wrongly filed out.

  • 写回答

3条回答 默认 最新

  • dsdeeaquu38538545 2015-05-23 23:06
    关注

    The issue where in the last test if (empty($Err["Err"])) { it should have been if (empty($Err)) {.

    Problem solved.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?