#### config.php ####
<?
//define the receiver of the email

define('TO_NAME','Jonathan Marshall'); //put your name
define('TO_EMAIL','[email protected]'); //put your email

define('TEMPLATE_PATH','template/default.php');


define('SMTP_HOST','smtp.mail.yahoo.co.uk'); //for example gmail: smtp.gmail.com
define('SMTP_USERNAME','[email protected]'); //put your email
define('SMTP_PASSWORD','######'); //put your password //Changed password to ###### for sharing code.
define('SUBJECT','Contact from your website Holding page'); //change if you want the subject

// Messages
define('MSG_INVALID_NAME','Please enter your name.');
define('MSG_INVALID_EMAIL','Please enter valid e-mail.');
define('MSG_INVALID_MESSAGE','Please enter your message.');
define('MSG_SEND_ERROR','Sorry, we can\'t send this message.');

?>

#### contact.php ####
<?php

require_once('config.php');
require_once('phpMailer/phpmailer.php');


// Sender Info
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);
$err = "";

// Check Info
$pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$^";
if(!preg_match_all($pattern, $email, $out)) {
$err = MSG_INVALID_EMAIL; // Invalid email
}
if(!$email) {
$err = MSG_INVALID_EMAIL; // No Email
}
if(!$message) {
$err = MSG_INVALID_MESSAGE; // No Message
}
if (!$name) {
$err = MSG_INVALID_NAME; // No name
}

//define the headers we want passed. Note that they are separated with \r\n
// $headers = "From: ".$name." <".$email.">\r\nReply-To: ".$email."" $body=include(_template_path);
$body=include(TEMPLATE_PATH);

$mail=new PHPMailer();

$mail->SetFrom($email,$name);
$mail->AddAddress('[email protected]','Jonathan Marshall');

//$mail->IsSMTP(); // enable SMTP
$mail->SMTPSecure='ssl';
$mail->SMTPAuth=true;
$mail->Host='smtp.mail.yahoo.co.uk';
$mail->Port=25;
$mail->Username='[email protected]';
$mail->Password='########'; // Changed password to ##### for security when sharing code.

$mail->Subject=SUBJECT;
$mail->MsgHTML($body);

// var_dump(TO_EMAIL);
// die();
if (!$err){

//send the email
// $sent = mail(TO_EMAIL,SUBJECT,$message,$headers);

if ($mail->Send()) {
// If the message is sent successfully print
echo "SENT";
} else {
// Display Error Message
echo MSG_SEND_ERROR;
}
} else {
echo $err; // Display Error Message
}
?>