<html>
<head>
<title>Send Mail Test</title>
<style><!--
BODY {font: normal 11px Arial, Verdana, Tahoma;}
.pd {margin-top: 15px; padding: 5px; background-color: #f4f4f4;}
--></style>
</head>
<body>
<?
/*
This sample send mail script is provided by Xceog.Net for free.
Please contact us for more information.
-------------------------------------------------------------------------
*/

include("config.php");

if(@$storeemail==1){
// Make a MySQL Connection
mysql_connect($mysqldomain, $mysqlusername, $mysqlpassword) or die(mysql_error());
mysql_select_db($mysqldbname) or die(mysql_error());
}

function validateemail($email){
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {return false;}else{return true;}
}

function sendmail($to,$subject,$message,$from){
//set sender's email here

$headers = "From: $from\r\nMIME-Version: 1.0\r\nContent-Type: text/HTML; charset=utf-8\r\nReply-To: $from\r\nX-Priority: 1\r\nX-MSmail-Priority: High\r\nX-Mailer: PHP/".phpversion();

if (mail($to, $subject, $message, $headers, "-f".$from)){return true;}else{return false;}
}

//== Set subject and message
$subject="Your mail subject here"; //put your subject in PHP Alphanumeric Format e.g. "Hello. This is a test..."
$msgfile="mailcontent.html"; //enter the filename which points to your mail content file in html format e.g. "mailmessage.html"

//========================== do not edit beyond this line
ob_start(); require($msgfile); $message=ob_get_contents(); ob_end_clean();
//== End retrieval

$selcontacts = @$_POST['selcontacts'];
$name = @$_POST['name'];
$email = @$_POST['email'];
//$from = stripslashes(@$_POST['fromemail']);
$from = "noreply@yourdomain.com"; //uncomment to use your domain email instead of user's email to send mails
//you are recommended to send using your domain's email. From email will not be supplied when the user uses manual invite option.

if(!$selcontacts){
$selcontacts = array();
if(stripslashes(@$_POST['manualinvite'])=="1"){
$tid=0;
foreach ($email as $t) {
array_push($selcontacts,$tid);
$tid++;
}
}
}

if(!$name){$name = array();}
if(!$email){$email = array();}

$i=0;
$contactcount=0;
foreach ($selcontacts as $contacts) {
$username = @$name[$contacts];
$contactemail = @$email[$contacts];
if(validateemail($contactemail)){
$contactcount++;

if(@$storeemail==1){
//DB Saves Email Addresses

$ok=1;
$mysql=mysql_query("SELECT * FROM contacts WHERE email='".addslashes($contactemail)."' LIMIT 1");
while($ary=@mysql_fetch_array($mysql)){$ok=0;}

if($ok==1){
mysql_query("INSERT INTO contacts
(email) VALUES('".addslashes($contactemail)."') ") 
or die(mysql_error());
}

}


	if(@sendmail($contactemail,$subject,$message,$from)){
	  echo htmlspecialchars($contactemail,ENT_QUOTES)."&ndash; <b>Mail Sent Successfully</b><br/>";
	}else{
	  echo htmlspecialchars($contactemail,ENT_QUOTES)."&ndash; <b>Send Mail Failed</b><br/>";
	}

$i++;
}
}

print "<div class=\"pd\"><b>Total of ".htmlspecialchars($contactcount,ENT_QUOTES)." selected email addresses retrieved</b></div>";
?>
</body>
</html>