-2

こんにちは、メールコードが完全に機能しています。私が望むのは、送信ボタンを押すと、メッセージが MAIL END と表示され、すべてのフォームが閉じることだけです....

電子メール アドレスの入力フォームが閉じ、同じページにメッセージが MAIL SENT. と表示され、他のページにリダイレクトされません。

<?php 
if(isset($_POST['btnsubmit'])) {
 $to = ($_POST['referrer_email']);
    $from = "abcz@gmail.com";
    $subject = "Hello";
 $message = "abcasdfasdfa asdfasdf ";

$headers = "MIME-Version: 1.0rn";
    $headers .= "Content-type: text/html; charset=iso-8859-1rn";
    $headers  .= "From: $from\r\n";mail($to, $subject, $message, $headers);
}
?>
<body>
<form name="ReferFriendForm" id="ReferFriendForm" method="post" action="" onSubmit="return validateForm()">
        <table class="forms" width="100%" border="0" style="margin: 0px; padding: 0px">
            <tbody style="margin: 0px; padding: 0px">
                <tr style="margin: 0px; padding: 0px">
                    <td colspan="2" style="margin: 0px; padding: 0px">Pass the 
                    Tel your friends and family about Net Telephone product and 
                    service<br style="margin: 0px; padding: 0px">
                    &nbsp;</td>
                </tr>
                <tr style="margin: 0px; padding: 0px">
                    <td class="requiredLabel" style="width: 44%; vertical-align: top; text-align: center; font-weight: bold; margin: 0px; padding-left: 0px; padding-right: 20px; padding-top: 3px; padding-bottom: 3px">
                    Your Name:</td>
                    <td class="field" style="vertical-align: top; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 3px; padding-bottom: 3px" width="54%" align="center">
                    <input size="35" name="referrer_name" id = "referrer_name"style="float: left; margin: 0px; padding: 0px"></td>
                </tr>
                <tr style="margin: 0px; padding: 0px">
                    <td class="requiredLabel" style="width: 44%; vertical-align: top; text-align: center; font-weight: bold; margin: 0px; padding-left: 0px; padding-right: 20px; padding-top: 3px; padding-bottom: 3px">
                    Your Email:</td>
                    <td class="field" style="vertical-align: top; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 3px; padding-bottom: 3px" width="54%" align="center">
                    <input size="35" name="referrer_email" style="float: left; margin: 0px; padding: 0px"> </td>
                </tr>
                <tr style="margin: 0px; padding: 0px">
                    <td class="requiredLabel" style="width: 44%; vertical-align: top; text-align: center; font-weight: bold; margin: 0px; padding-left: 0px; padding-right: 20px; padding-top: 3px; padding-bottom: 3px">
                    Friend 1 Email:</td>
                    <td class="field" style="vertical-align: top; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 3px; padding-bottom: 3px" width="54%" align="center">
                    <input size="35" name="f1email" style="float: left; margin: 0px; padding: 0px"> 
                    <tr style="margin: 0px; padding: 0px">
                    <td class="requiredLabel" style="width: 44%; vertical-align: top; text-align: center; font-weight: bold; margin: 0px; padding-left: 0px; padding-right: 20px; padding-top: 3px; padding-bottom: 3px">
                    Friend 2 Email:</td>
                    <td class="field" style="vertical-align: top; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 3px; padding-bottom: 3px" width="54%" align="center">
                    <input size="35" name="f2email" style="float: left; margin: 0px; padding: 0px"> 
                    <tr style="margin: 0px; padding: 0px">
                    <td class="requiredLabel" style="width: 44%; vertical-align: top; text-align: center; font-weight: bold; margin: 0px; padding-left: 0px; padding-right: 20px; padding-top: 3px; padding-bottom: 3px">
                    Friend 3 Email:</td>
                    <td class="field" style="vertical-align: top; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 3px; padding-bottom: 3px" width="54%" align="center">
                    <input size="35" name="f3email" style="float: left; margin: 0px; padding: 0px"> 
                    <tr style="margin: 0px; padding: 0px">
                    <td class="requiredLabel" style="width: 44%; vertical-align: top; text-align: center; font-weight: bold; margin: 0px; padding-left: 0px; padding-right: 20px; padding-top: 3px; padding-bottom: 3px">
                    Friend 4 Email:</td>
                    <td class="field" style="vertical-align: top; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 3px; padding-bottom: 3px" width="54%" align="center">
                    <input size="35" name="f4email" style="float: left; margin: 0px; padding: 0px"> 
                    <tr style="margin: 0px; padding: 0px">
                    <td class="requiredLabel" style="width: 44%; vertical-align: top; text-align: center; font-weight: bold; margin: 0px; padding-left: 0px; padding-right: 20px; padding-top: 3px; padding-bottom: 3px">
                    Friend 5 Email:</td>
                    <td class="field" style="vertical-align: top; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 3px; padding-bottom: 3px" width="54%" align="center">
                    <input size="35" name="f5email" style="float: left; margin: 0px; padding: 0px"> 


                     </td>
                </tr>
                <tr style="margin: 0px; padding: 0px">
                    <td style="margin: 0px; padding: 0px" align="center">&nbsp;</td>
                    <td style="margin: 0px; padding: 0px" width="54%" align="center">
                    <br style="margin: 0px; padding: 0px">
                    <input type="submit" name="btnsubmit" id="btnsubmit" value="&nbsp;&nbsp;&nbsp;&nbsp;Send email&nbsp;&nbsp;&nbsp;&nbsp;" style="float: left; margin: 0px; padding: 0px"></td>
                </tr>

        </table>
    </form>
</div>
</body>
</html>
4

1 に答える 1

1

次のようにコードを書く必要があります。

<?php
   if(!isset($_POST['btnsubmit'])){
      //write your html form here
   }else{
     $to = ($_POST['referrer_email']);
     $from = "abcz@gmail.com";
     $subject = "Hello";
     $message = "abcasdfasdfa asdfasdf ";

     $headers = "MIME-Version: 1.0rn";
     $headers .= "Content-type: text/html; charset=iso-8859-1rn";
     $headers  .= "From: $from\r\n";

     if(mail($to, $subject, $message, $headers)){
        echo "MAIL SENT";
     }

   }
?>
于 2012-06-11T03:16:39.417 に答える