您好我的电子邮件代码完美无缺。我想要的是,当我按下发送按钮时,消息应该显示MAIL END并且所有表单都应该关闭....
输入您的电子邮件地址表格应该关闭并在同一页面上显示邮件MAIL SENT.without重定向到任何其他页面。
<?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">
</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"> </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=" Send email " style="float: left; margin: 0px; padding: 0px"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
答案 0 :(得分: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";
}
}
?>