Page 1 of 1
simple mail function questioni
Posted: Mon Sep 10, 2007 11:16 am
by dru_nasty
Code: Select all
<?php
$to = "my email";
$subject = "Testing PHP on Server";
$message = "Mail is working";
if(submit){
if(mail($to,$subject,$message)){
echo "mail sent";
}else{
echo "mail NOT sent";
}
}
?>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="<? echo($PHP_SELF) ?>">
<input type="submit" value="Submit">
</form>
</body>
</html>
My question is why when i hit this page, the "mail sent" echo is already showing before clicking the submit button?
How can i fix this so no echo shows until after the mail function is ran?
Thanks!!
Posted: Mon Sep 10, 2007 12:50 pm
by anjanesh
Change if(submit) to
if (isset($_POST['submit']))
Posted: Mon Sep 10, 2007 12:59 pm
by dru_nasty
Code: Select all
<html>
<head>
<title></title>
</head>
<body>
<?php
if ($_POST['submit']=='Submit')
{
$to = "address here";
$subject = "Testing PHP Server";
$message = "Mail is working";
$header = 'From: address here' . "\r\n";
if(mail($to,$subject,$message,$header))
{
echo "mail sent";
}
else
{
echo "mail NOT sent";
}
}
?>
<form method="post" action="<? echo($PHP_SELF) ?>">
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
Thx for the reply, I just actually figured it out and got it working