<?php 
ini_set('display_errors', 1);
error_reporting('E_ALL & ~E_NOTICE'); // Turn E_NOTICES OFF.

if (!extension_loaded('openssl'))
{
    echo "<h3>System Error</h3>This script requires that you enable the OpenSSL PHP Extension. You can do that<br>by uncommenting <b>;php_openssl.dll</b> in your <b>php.ini</b> file.";
    exit; // Exit the script if the extension is not found.
}

// Set these variables
$gmail_username = "username@gmail.com"; // leave @gmail.com after username
$gmail_password = "password";
$send_to = "my_email@gmail.com"; // deliver correspondence to this address

/*
User variables:
$_REQUEST['name']
$_REQUEST['email'] 
$_REQUEST['subject'] 
$_REQUEST['message'] 
*/

require("./phpmailer.php"); // Path to phpmailer.php
$mail = new PHPMailer();

// LOGIN
$mail->IsSMTP();            // set mailer to use SMTP
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = $gmail_username;  // SMTP username
$mail->Password = $gmail_password; // SMTP password

// EMAIL FROM
$mail->From = $_REQUEST['email'];
$mail->FromName = $_REQUEST['name'];

// EMAIL TO
$mail->AddAddress($send_to);

// REPLY TO - maybe send copy to user ???
// $mail->AddReplyTo($myemail, $myname);

// You can add cc's and bcc's like this:
// $mail->AddCC("friend3@gmail.com")
// $mail->AddBCC("friend4@aol.com");

// You can add attachments like this:
// $mail->AddAttachment("/var/tmp/file.tar.gz");
// $mail->AddAttachment("/tmp/image.jpg", "new.jpg");

// Extended features set at http://phpmailer.sourceforge.net/docs/elementindex_PHPMailer.html

$date = date("l, F j, Y");
$time = date("g:ia");

$mail->WordWrap = 70;   // set word wrap to 50 characters
$mail->IsHTML(true);    // set email format to HTML

$messagebody = htmlentities($_REQUEST['message']);

$mail->Subject = $_REQUEST['subject'];
$mail->Body    = "<PRE>Form Submission from <a href=\"$_SERVER[HTTP_REFERER]\">$_SERVER[HTTP_REFERER]</a>

---INFO-------------------
Date:     {$date} @ {$time} (server time)
IP:       {$_SERVER['REMOTE_ADDR']}

---SENDER-----------------
Name:     {$_REQUEST['name']}
Email:    <a href=\"mailto:{$_REQUEST['email']}\">{$_REQUEST['email']}</a>

---MESSAGE----------------
{$messagebody}
---MESSAGE END------------</PRE>";

// Mail NOT sent!
if(!$mail->Send())
{echo "We encountered an error sending your correspondence.<BR><BR>".
"Mailer Error Info: " . $mail->ErrorInfo . "<BR><BR><BR>".
"<B>Just click this link to open your favorite email client. All of the information should automatically be entered in.</B><BR>".
"Email Link: <a href=\"mailto:{$send_to}?subject={$_REQUEST['subject']}&body=".rawurlencode($_REQUEST['message'])."\">Click here</a><BR><BR><HR><BR>".
"Here is the original message you were trying to send me:<BR><BR>";}

// Mail sent!
else {echo "Your mail was sent successfully.<HR>".
"Here is your message I should be receiving soon.<BR><BR>";}

echo "<PRE>".
"Name:    <b>$_REQUEST[name]</b><BR>".
"Email:   <b>$_REQUEST[email]</b><BR>".
"Subject: <b>{$_REQUEST['subject']}<BR>".
"</PRE>".
"<TEXTAREA READONLY rows=\"15\" cols=\"80\" wrap=\"off\">".htmlentities($_REQUEST['message'])."</TEXTAREA>";
?>
