Thursday, December 16, 2010

Send E-Mail

<?php
function spamcheck($field)  {
   $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  if(filter_var($field, FILTER_VALIDATE_EMAIL))    {
    return TRUE;
    }  else    {
    return FALSE;
    }
  }

if (isset($_REQUEST['email']))  {   //if "email" is filled out, proceed
  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)    {
    echo "Invalid input";
    }  else    {    //send email
    $email = $_REQUEST['email'] ;
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['message'] ;
    mail("bala@gmail.com", "Subject: $subject",
    $message, "From: $email" );
    echo "Thank you for using our mail form";
    }
  }
else  {    //if "email" is not filled out, display the form
  echo "<form method='post' action='secureMail.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

No comments:

Post a Comment