<?php

function mailOut($to, $from, $from_name, $subject, $body)
{
	//echo "entered";


	require("class.phpmailer.php");

		//echo "entered2";
	
	$mail = new PHPMailer();

	$mail->IsSMTP(true);                                      // set mailer to use SMTP
	$mail->Host = "smtp.gmail.com";  // specify main and backup server
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	$mail->Username = "realcompemail@gmail.com";  // SMTP username
    $mail->Password = "BrentAnos7282!!"; // SMTP password
	$mail->SMTPSecure = "ssl"; // secure transfer enabled REQUIRED for GMail
	$mail->SMTPDebug = 1;
	$mail->Port = 465;


	$mail->From = $from; //
	$mail->FromName = $from_name; //
	
	 
	$pieces = explode(";", $to);
	
	foreach ($pieces as &$value) 
	{
		if (strlen($value) != 0)
			$mail->AddAddress($value, $value);
	}
	
	
	//$mail->AddAddress($to, $to); // this should be the user's email address
	
	
	//$mail->AddBCC("jocc@hotmail.com"); // this should be the office email address

	$mail->WordWrap = 100;                                 // set word wrap to 50 characters
	//$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
	//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
	$mail->IsHTML(true);                                  // set email format to HTML

	$mail->Subject = $subject; //"Here is the subject";
	$mail->isHTML(true);
	$mail->Body    = $body; //"This is the HTML message body <b>in bold!</b>";
	//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

		//echo "entered3";
	
	if(!$mail->Send())
	{
		//echo "Message could not be sent. <p>";
		//echo "Mailer Error: " . $mail->ErrorInfo;
		//exit;
	}

	//echo "Message has been sent";

}

Function make()
{
	$ret =  "<html>".
			"<body>" . 
			"<span font=\"Arial\" color=\"gray\">" .
			"<p>" .
			"<b>Online Enquiry:</b> " .  mysql_escape_string($_POST['fname']) . " " .  mysql_escape_string($_POST['ltname']) . " | " .  mysql_escape_string($_POST['subject'])  . "<br/>" .
			"</p>" .
			"<p>"  .
			"<b>Email:</b> " .  mysql_escape_string($_POST['email']) . "<br/>" .
			"<b>Phone:</b> " . mysql_escape_string($_POST['phone']) . "<br/>" .
			"<b>Company:</b> " . mysql_escape_string($_POST['subject']) . "<br/>" .
			"<b>Message:</b> " . mysql_escape_string($_POST['message']) . "<br/>" .
			"</p>" .
			"</span>" .
			"</body>" .
			"</html>"; 
			
	return $ret;
	 
	
	
}


$fname = mysql_escape_string($_POST['fname']);
$lname = mysql_escape_string($_POST['lname']);
$email = mysql_escape_string($_POST['email']);
$phone = mysql_escape_string($_POST['phone']);
$subject = mysql_escape_string($_POST['subject']);
$message = mysql_escape_string($_POST['message']);


mailOut("con@builteq.com.au", "Builteq Website Enquiry", "Builteq Website Enquiry", "Builteq Website Enquiry", make());

header("Location: http://www.builteq.com.au/contact.php?rt=1#ll");

?>
