Location: PHPKode > scripts > Contact Form PHP Ajax Script > contact_mail.php
<?php
// Contact Form - http://www.coursesweb.net/php-mysql/
if(!isset($_SESSION)) session_start();        // starts session, if not already started

/** HERE ADD YOUR DATA **/

$to = 'hide@address.com';			// Receiver e-mail address (to which the email will be send)

// If you want to use the SMTP server from GMail, set the value 1 at $gmail variable
// Add your GMail address at the $gmail_user, and add the password for this e-mail at $gmail_pass
// If you want to use the local mail server, no change $gmail=0, $gmail_user, and $gmail_pass
$gmail = 0;
$gmail_user = 'hide@address.com';
$gmail_pass = 'gmail_password';


/** From this line you no need to modify **/

// Check the session that limits to can be send only an e-mail in 5 minutes, also useful anti-refresh
if(isset($_SESSION['limit_contact']) && $_SESSION['limit_contact']>(time()-300)) {
  echo 'Error: You can send only a message at 5 minutes.<br />Wait '.($_SESSION['limit_contact']-time()+300).' seconds';
  exit;
}

// Check the anti-spamm code
if(isset($_POST['anti_spam']) && isset($_POST['anti_spam1']) && $_POST['anti_spam']==$_POST['anti_spam1']) {
  // Check if all necessary data are received by post
  if(isset($_POST['nume']) && isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['message'])) {
    // remove external whitespace and tags
    $_POST = array_map("trim", $_POST);
	  $_POST = array_map("strip_tags", $_POST);

    // gets form data
    $nume = $_POST['nume'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    $body = 'E-mail from Contact form, sent by: '.$nume. "\n His /Her e-mail address: ". $email. "\n\n"
      .'message: '.$message;

    // if $gmail=1, uses the gmail_sender() function (of the phpmailer class) to send the email via GMail
    // Otherwise, uses the PHP mail() function
    if($gmail===1) {
      include('gmail/gmail.php');    // Include the file with the gmail_sender() function

      // Calls the gmail_sender() function, and store its response
      $send = gmail_sender($to, $gmail_user, $gmail_pass, $subject, $body, $email, $nume);
    }
    else {
      $from = 'From: '. $email;
      // uses the PHP mail() function, If sending successfully, set $send='sent', otherwise defines 'Error'
      if(mail($to, $subject, $body, $from))  $send = 'sent';
      else $send = 'Error: The server could not send the email.';
    }

    // If the email is sent, display the confirmation. Otherwise returns the error
    if($send=='sent') {
      // Set a session used to block the re-sending to an eventual refresh or in less than 5 minutes
      $_SESSION['limit_contact'] = time();

      $re = '<p><b>Your message was successfully sent, will be answered as soon as possible.</b></p>
      <p><b><i>Thank you for your interest.</i></b></p>
              <p>If you wish, visit: <a href="http://www.coursesweb.net/">CoursesWeb.net</a></p>';
    }
    else $re = $send;
  }
  else $re = 'Error: not all form fields.';
}
else $re = 'Error: Incorrect verification code.';

echo $re;
?>
Return current item: Contact Form PHP Ajax Script