Below is the modified code:
<div align="right">
<?
//$_POST = "";
echo '<pre>';
print_r($_POST);
echo '</pre>';
$postdate = "";
$headers = "";
$message = "";
$name = "";
$email = "";
$sub = "";
$to = "";
?>
<form action="?do=msgdiv" method="post">
<input type="button" name="button" value="Send a Message" class="submit_2"
onclick="document.getElementById('msgdiv').style.display = 'block'; document.getElementById('fromid').focus(); "/>
</form>
<?
if(isset($_POST['submit']))
{
$postdate = date('Y-m-d H:i:s');
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.trim($_POST['fromid']);
$headers .= '<'.trim($_POST['emailid']).'>'."\r\n";
$message = trim($_POST['msg']);
$name = $_POST["fromid"];
$email = $_POST["emailid"];
$sub = 'Profile of the week response';
$to = 'edwin@guyseek.com'; //.'<'.'edwin@guyseek.com'.'>'."\r\n";
mail($to,$sub,$message,$headers);
unset($_POST['submit']);
}
?>
</div>
<div align="left" id="msgdiv" style="display:none;padding:10px; position:absolute;position:absolute;
top:1700px; left:150px; width:490px; height:400px; background-color:#FFCC00">
<form action="?do=index" method="post" > <!--enctype="multipart/form-data" -->
<ul>
<li>
<label><strong> From :<strong/></label>
<input type="text" name="fromid" id="fromid" value=" " style="width:260px;" maxlength="49"/> Enter your name.
</li><br />
<li>
<label><strong> Email :<strong/></label>
<input type="text" name="emailid" id="emailid" value=" " style="width:260px;" maxlength="49"/> Enter your email.
</li><br />
<li>
<label><strong>Type your message below:<strong/></label>
<textarea name="msg" id="msg" cols="30" rows="10" style="width:320px;"></textarea><br />
</li><br />
<li>
<label> </label>
<INPUT type="submit" name="submit" value="Submit" style="height:25px" >
<INPUT type="reset" name="reset" value="Reset" style="height:25px" >
<input type="button" style="height:25px" value="Cancel" onclick="document.getElementById('msgdiv').style.display = 'none';" />
</li>
</ul>
</form>
<?
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
</div>
On loading the page, an email is sent without clicking "Send a Message" and the following is displayed:
Array
(
[fromid] => this is a test
[emailid] => this is a test
[msg] => this is a test
[submit] => Submit
)
Send a Message (button)
Everytime page is refreshed, an email is sent, again without clicking "Send a Message"
Is there a way to unset the $POST variable so that it does not pass the isset "if test" everytime the page is reloaded/refreshed - or should i be using a different "if test" other than isset($POST)?