此代码在PHP 5.3中运行良好,但我无法弄清楚如何在LAMP服务器上使用它在PHP 5.5.9中运行。我试过四处寻找,但没有找到任何解决办法。有任何解决方法吗?
因此;用户看到来自正确的,没有它总是说邮件被发送的事实,即使他们点击提交按钮。其次,它最终应发送的邮件不会被发送,也没有任何反应。
<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>
问题是在5.5.9上它不发送信息邮件(给我),用户在点击sumbit按钮之前获取邮件发送的信息,即使它&# 39; s错误地提出了。
答案 0 :(得分:0)
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"
- &gt; action=""
if (empty($Err["Err"])) {
- &gt; $ Err可能仍然是“1”(没有数组)将发出警告但请先告诉我们出了什么问题! 打开代码开头显示错误/警告:
ini_set('error_reporting', E_ALL);
ini_set("display_errors", "1");
答案 1 :(得分:0)
我的第一个猜测是,当您的PHP 5.3服务器配置为发送电子邮件时,您的PHP 5.5.9不是。简单测试 - 使用硬编码值调用mail()
。
甚至在他们点击提交按钮之前
我不确定你的意思是什么,但也许你在用AJAX做点什么。查看浏览器的控制台日志,查看所有HTTP请求和响应。
答案 2 :(得分:0)
上次测试if (empty($Err["Err"])) {
应该是if (empty($Err)) {
的问题。
问题解决了。