当html页面加载/刷新时,它会触发php文档.我不想那样


When html page loads/refreshes it triggers php document. I don't want that

我有网站(dastiche.kz),并有通讯订阅。我修改了我的订阅,添加了一些"iframe",这样就可以在不重定向到另一个页面的情况下显示echo。现在一切都很好,但我现在有一个烦人的问题。每次我去我的主页(订阅表单所在的地方)或只是刷新它,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.");
?>

在你的代码前面加上一个条件

if(isset($_POST['Submit']))
{
    // here put your complete php code
}

这将检查是否收到了名称为Submit的POST请求。所以代码将在你按下提交按钮时执行,比如

<?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");
}
?>