我有网站(dastiche.kz)并且有订阅时事通讯。我已经修改了一些我的订阅,添加了一些" iframe",以便在不重定向到另一个页面的情况下显示回声。现在一切都很好,但我现在遇到了烦人的问题。每次我去我的主页(订阅表单所在的位置)或只是刷新它,php被触发,我收到空白电子邮件,好像有人订阅了。我做错了什么?
<iframe name="myiframe" src="myiframe.php" width="100%" height="60px" frameborder="0"></iframe>
<form method="POST" action="myiframe.php" class="subscribe" target="myiframe">
<p><input type="text" name="Name" maxlength="10" style="font-family:'Times New Roman', Times, serif" value="Ваше имя" onfocus="if (this.value == 'Ваше имя') {this.value = '';}" onblur="if (this.value == '') {this.value ='Ваше имя';}" class="line"></p>
<p><input type="email" name="Email" maxlength="40" style="font-family:'Times New Roman', Times, serif" value="Ваш email" onfocus="if (this.value == 'Ваш email') {this.value = '';}" onblur="if (this.value == '') {this.value ='Ваш email';}" class="line"></p>
<p><input type="image" value="submit" name="Submit" src="img/subscribe.png" class="imgsub"></p>
</form>
<?php
Header("Content-Type: text/html; charset=utf-8");
$recipient = "order@dastiche.kz";
$subject = "Subscriber";
$name = $_POST['Name'];
$email = $_POST['Email'];
$location = "index.html";
$sender = $recipient;
$body .= "Name: ".$_REQUEST['Name']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
if (($name != "") and ($email != ""))
// Если существуют проверяем...
{
if ((strlen($name) >= 2) and (strlen($name) <= 25))
{
$name = stripslashes($name);
$name = html_entity_decode($name);
$name = strip_tags($name);
}
else
{
echo " something is wrong with name field ";
echo "<center><input name='back' type='button' value='get back'
onclick= 'javascript:history.back()'></center>";
}
if (eregi("^[._a-zA-Z0-9-]+@[.a-zA-Z0-9-]+.[a-z]{2,6}$", $email))
{
$email = stripslashes($email);
$email = htmlspecialchars($email);
$email = strip_tags($email);
}
else
{
echo "There are some mistakes in the \"E-mail\" field";
echo "<center><input name='back' type='button' value='try again'
onclick= 'javascript:history.back()'></center>";
}
}
// Если не существуют выводим сообщение...
else
{
echo "Заполните следующие поля:";
}
if (($name) and ($email))
{
echo "Спасибо за подписку!";
}
mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be sent.");
?>
答案 0 :(得分:0)
正如我评论的那样,在你的代码上面加上一个条件
if(isset($_POST['Submit']))
{
// here put your complete php code
}
这将检查收到的POST请求是否为Submit
。所以当您按下提交按钮时
<?php
if(isset($_POST['Submit']))
{
Header("Content-Type: text/html; charset=utf-8");
$recipient = "order@dastiche.kz";
$subject = "Subscriber";
$name = $_POST['Name'];
$email = $_POST['Email'];
$location = "index.html";
$sender = $recipient;
$body .= "Name: ".$_REQUEST['Name']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
if (($name != "") and ($email != ""))
// ???? ?????????? ?????????...
{
if ((strlen($name) >= 2) and (strlen($name) <= 25))
{
$name = stripslashes($name);
$name = html_entity_decode($name);
$name = strip_tags($name);
}
else
{
echo " something is wrong with name field ";
echo "<center><input name='back' type='button' value='get back'
onclick= 'javascript:history.back()'></center>";
}
if (eregi("^[._a-zA-Z0-9-]+@[.a-zA-Z0-9-]+.[a-z]{2,6}$", $email))
{
$email = stripslashes($email);
$email = htmlspecialchars($email);
$email = strip_tags($email);
}
else
{
echo "There are some mistakes in the \"E-mail\" field";
echo "<center><input name='back' type='button' value='try again'
onclick= 'javascript:history.back()'></center>";
}
}
// ???? ?? ?????????? ??????? ?????????...
else
{
echo "????????? ????????? ????:";
}
if (($name) and ($email))
{
echo "??????? ?? ????????!";
}
mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be Sent");
}
?>