You could wrap your $_REQUEST in something like
if(isset($_POST['email']) && isset($_POST['message']))
{
$to = "[email protected]";
$subject = "Aquadual Contact Form Message";
$email = $_POST['email'];
$message = $_POST['message'];
mail($to,$subject,$message,"From: $email" );
}
I wouldn't use $_REQUEST by the way. you snag all $_GET, $_POST, $_SESSION and $_COOKIE with that and if you have a conflict it may choose the wrong one. ie: $_POST['email'] is set as well as $_SESSION['email']. You may send the wrong person an email.
Per request - this is a way to return the user after mail:
<?php // this is assumed to be sendmail.php
$message = array();
if(isset($_POST['email']) && isset($_POST['message']))
{
$to = "[email protected]";
$subject = "Aquadual Contact Form Message";
$email = $_POST['email'];
$message = $_POST['message'];
if(mail($to,$subject,$message,"From: $email" ))
$message = array(true, 'Thank you for your message.');
else
$message = array(false, 'Email failed. Please try again.');
}
if(!empty($message))
{
if($message[0] === true)
echo '<span style="color:green;">'.$message[1].'</span>';
else
echo '<span style="color:red;">'.$message[1].'</span>';
}
?>
html form here
I would probably suggest setting the message and form to a session variable so the user can't send more than 3 messages per session - to avoid spamming. Something like:
<?php
session_start();
if(!$_SESSION['count'])
$_SESSION['count'] = 0;
if(isset($_POST['email']) && isset($_POST['message']) && $_SESSION['count'] < 4)
{
$to = "[email protected]";
$subject = "Aquadual Contact Form Message";
$email = $_POST['email'];
$message = $_POST['message'];
if(mail($to,$subject,$message,"From: $email" ))
{
$_SESSION['count'] = $_SESSION['count'] + 1;
$message = array(true, 'Thank you for your message.');
}
else
$message = array(false, 'Email failed. Please try again.');
}
if(!empty($message))
{
if($message[0] === true)
echo '<span style="color:green;">'.$message[1].'</span>';
else
echo '<span style="color:red;">'.$message[1].'</span>';
}
?>
Hope it helps