<?
function get_email1($user_id) {
$query="SELECT email FROM user WHERE id='$user_id'";
		$res=mysql_query($query);
		list($email)=mysql_fetch_row($res);
		   return $email;
}
function get_nameuser($user_id)
{
	$query="SELECT first_name FROM user WHERE id='$user_id'";
		$res=mysql_query($query);
		list($first_name)=mysql_fetch_row($res);
		   return $first_name;
}

function getUserById($uid)
{
	$sql="select * from user where id='$uid'";
	$res=mysql_query($sql) or die(mysql_error());
	$row=mysql_fetch_object($res);
	return $row;
}
function getnewsletter($uid)
{
	$sql="select * from newsletter_subscribe where uid='$uid'";
	$res=mysql_query($sql) or die(mysql_error());
	$row=mysql_fetch_array($res);
	return $row;
}

function encodeHeader($input, $charset = 'ISO-8859-1')
{
    preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches);
    foreach ($matches[1] as $value) {
        $replacement = preg_replace('/([\x20\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
        $input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
    }   
	return $input;
}

function send_refer_bids($receiverid)
{
    $userdt=getUserById($receiverid);	
	$to=$userdt->email;		
	
	$sub= "Free bids to refer a friend";
	
$body="<html><title>"._DOOBD_INVT_."</title><body>
<center>
<div style='width:500px'>

<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._WLCM_TLOOP_."</div>
<div style='height:5px; background-color:#FFAE0D'></div>
<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._HII_." !<br>You have got free bids ...<br><br>"._PLS_FLLNK_." <br>
	<a href='"._BASEURL_."/>"._BASEURL_."/</a><br>	
	<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
</div>
</center>
</body>
</html>"; 

$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";
mail($to,$sub,$body,$headers);		
}

function confirm_refer_friend($referid)
{
 $rec = mysql_fetch_array(mysql_query("select uid,email from invite_friend where id='$referid'"));
 $sender=get_nameuser($rec['uid']);
 $refer=explode('@',$rec['email']);
 $to=_ADMIN_MAIL_;	
	
	$sub= "Relation Approved";
	 $body="<html><title>"._DOOBD_INVT_."</title><body>
<center>
<div style='width:500px'>

<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._WLCM_TLOOP_."</div>
<div style='height:5px; background-color:#FFAE0D'></div>
<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._HII_." !<br>$sender and $refer[0] relation approved.<br><br>Please give  free bids  to $sender. <br>
<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
</div>
</center>
</body>
</html>";

$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";
mail($to,$sub,$body,$headers);	

}

function send_invitation($uid,$email,$ccode)
{
    $userdt=getUserById($uid);	

	$to=$email;	
	
	$rec=mysql_fetch_array(mysql_query("select invite_mail from admin_mail"));
	
	$sub=encodeHeader(_INVT_UTO_JNDB_);
	 $body="<html><title>"._DOOBD_INVT_."</title><body>
<center>
<div style='width:500px'>

<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._WLCM_TLOOP_."</div>
<div style='height:5px; background-color:#FFAE0D'></div>
<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._HII_." !<br>"._U_HB_INVDBY_." ".$userdt->uname."\n<br><br>"._PLS_FLLNK_." <br>
	<a href='"._BASEURL_."/register.php?refer=$ccode'>"._BASEURL_."/register.php?refer=$ccode</a><br>
	".nl2br($rec[0])."
	<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
</div>
</center>
</body>
</html>"; 

$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";
mail($to,$sub,$body,$headers);		
}

function admin_refer_friend($uid,$email,$ccode)
{
    $userdt=getUserById($uid);	

	$to=_ADMIN_MAIL_;	
	
	$rec=mysql_fetch_array(mysql_query("select invite_mail from admin_mail"));
	
	$sub= "Refer a friend";
	$body="<html><title>"._DOOBD_INVT_."</title><body>
<center>
<div style='width:500px'>

<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._WLCM_TLOOP_."</div>
<div style='height:5px; background-color:#FFAE0D'></div>
<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._HII_." !<br>".$userdt->uname."<br/><br> refer a friend ".$email.".
	<br><br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
</div>
</center>
</body>
</html>"; 
$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";
mail($to,$sub,$body,$headers);		
}



function register_mail($fname,$email,$ccode,$uid)
{	
	 $to=$email;
	$userdt=getUserById($uid);	
	$rec=mysql_fetch_array(mysql_query("select reg_mail from admin_mail"));
	$sub=encodeHeader(_THNK_YR_REGTR_);
	$body="<html><title>"._REGST_SCCFL_."</title><body>
<center>
<div style='width:500px'>

<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._WLCM_TLOOP_."</div>
<div style='height:5px; background-color:#FFAE0D'></div>
<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._DEAR11_." ".$fname."!<br>"._THNK_DB_REG_."\n<br><br>"._PLS_CNFR_YRREG_."<br>
	<a href='"._BASEURL_."/confirm.php?confirm=$ccode'>"._BASEURL_."/confirm.php?confirm=$ccode</a><br>"._U_MAY_LGN_." "._BASEURL_." <br><br>"._USR_NM_." ".$userdt->email."<br>"._PWD11_." ".$userdt->password."<br>
	".nl2br($rec[0])."
	<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
</div>
</center>
</body>
</html>"; 
$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";

mail($to,$sub,$body,$headers);
}


function confirm_reg($c_code)
{
   $qq="select  uname,email from user where ccode='$c_code'";
   list($fname,$email)=mysql_fetch_array(mysql_query($qq));
    $to=$email;	
	$rec=mysql_fetch_array(mysql_query("select confirm_reg_mail from admin_mail"));
	$sub=_CNFR_YR_REG_;		
$body="<html><title>"._REGST_SCCFL_."</title><body>
<center>
<div style='width:500px'>
<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>Greenfair Registration Confirmation</div>
<div style='height:5px; background-color:#FFAE0D'></div>
<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._DEAR11_." ".$fname."!<br><br>Your registration has been confirmed successfully.<br>You may login to Greenfair at any time at 
<a href='"._BASEURL_."'> "._BASEURL_."</a><br><br>
".nl2br($rec[0])."
<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
</div>
</center>

</body>
</html>";
$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";

mail($to,$sub,$body,$headers);	
	
}


function forget_mail($fname,$email,$pass,$uid)
{
	
	
	$to=$email;
	$rec=mysql_fetch_array(mysql_query("select forget_mail from admin_mail"));
	$userdt=getUserById($uid);	
	$sub=encodeHeader(_FORFT_PWD_);
	$body="<html><title>"._FORFT_PWD_."</title><body>
<center>
<div style='width:500px'>

<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._WLCM_TLOOP_."</div>
<div style='height:5px; background-color:#FFAE0D'></div>
<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>Dear ".ucfirst($fname)."!<br><br>"._U_MAY_LGN_." "._BASEURL_." <br><br>"._USR_NM_." ".$userdt->email."<br>"._PWD11_." ".$userdt->password."<br>
".nl2br($rec[0])."
<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
</div>
</center>
</body>
</html>"; 
$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";
mail($to,$sub,$body,$headers);		
}



function send_newsletter($sub,$desc,$uid)
{
	
	
	$userdt=getUserById($uid);
	$to=$userdt->email;	
	$uname=$userdt->uname;
	 
	//$sub= "Thank you for Newsletter Subscribe";
	 $body="<html><title>"._NWSLTR_SBSCRB_."</title><body>
<center>
<div style='width:500px'>
<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>".ucfirst($sub)."</div>
<div style='height:5px; background-color:#FFAE0D'></div>
<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>Dear ".ucfirst($uname).",<br>".$desc."<br>
	<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
</div>
</center>
</body>
</html>"; 
$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";
mail($to,$sub,$body,$headers);		
}

function mass_mailing($subject,$message1)
{
	
$subject= ($subject);
$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";			
				
			   $sc="select email,uname from user where email!='' and confirm='1' and deactive='0' and blocked='0'";
				$res=mysql_query($sc);
				while($data=mysql_fetch_array($res))
				 {
	 $message = "
						<html>
						<body>
						<center>
						<div style='width:500px'>
						
						<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>
						
						".ucfirst($subject)."</div>
						<div style='height:5px; background-color:#FFAE0D'></div>
						<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>Dear ".ucfirst($data['uname']). ", 
						<br/>
						".ucfirst($subject)."<br/>
						".
						$message1."<br/>
					
						<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
						</div>
						</center>
						
						</body>
						</html>"; 
				 
				 
				 
					 $all_mail = $data['email'];
					 mail($all_mail,$subject,$message,$headers);
					 
				}	
}


function invite_user($touser,$message1)
{

$headers ="From:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Reply-To:"._ADMIN_MAIL_."<"._ADMIN_MAIL_."> \r\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\n";
				$subject .="Greenfair Invitation";
				$touserarr = explode(",",$touser);
				
				for($i=0;$i<count($touserarr); $i++)
				{
		$message = "
						<html>
						<body>
						<center>
						<div style='width:500px'>
						
						<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>"._WLCM_TLOOP_."</div>
						<div style='height:5px; background-color:#FFAE0D'></div>
						<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>Dear
						<br/>".
						$message1."
						
						
						<br>"._THNK_U_."!<br>"._MOMS_TEAM_."</div>
						</div>
						</center>
						
						</body>
						</html>"; 
				
				
				
				   $to_email = $touserarr[$i];
				   mail($to_email,$subject,$message,$headers);
				
				}
				
				   
  }
  
  
  function feedback_email($uid,$feedpre,$feed_dec,$tel_number){
            $to=_ADMIN_MAIL_;
			$rec=mysql_fetch_array(mysql_query("select feedback_mail from admin_mail"));
			$uname=get_fieldval(id,uname,user,$uid)."<br/>".$tel_number;
		 	$from=get_fieldval(id,email,user,$uid)."<br/>";
		    $subject=$feedpre;
		    $headers ="From:". $from. "<".$from."> \r\n";
			$headers .= "Reply-To:". $from. "<".$from ."> \r\n";
			$headers .= "Content-Transfer-Encoding: 8bit\n";
			$headers .= "MIME-Version: 1.0\n";
			$headers .= "Content-type: text/html; charset=utf-8\n";
	        $headers.="Date: ".date("r")."\r\n";
	        $headers.="Subject: ".$subject."\r\n";
			$message="<html>
					<body>
					<center>
					<div style='width:500px'>
					<div style='height:20px; padding:10px; color:#FFFFFF; background-color:#5CB115; font-size:20px;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>USER FEEDBACK MAIL</div>
<div style='height:5px; background-color:#FFAE0D'></div>
					
					<div style='padding:10px; border:1px solid #CCCCCC; font-size:12px; color:#333333;font-family: 'lucida grande', tahoma, verdana, arial, sans-serif' align='left'>
					
					  <p>".$subject. " <br/>
					 ".$feed_dec."<br/>".
					"<a href='"._BASEURL_."/feedback.php?auction=".$uid."'>"._BASEURL_."/feedback.php?auction=".$uid."</a><br>
					
					
					<br>"._THNK_U_."!<br>".$uname."<br><br></div>
					</div>
					</center>
					
					</body>
					</html>";
			
			@mail($to,$subject,$message,$headers);
			header("Location:feedback.php?auction=$uid");
			}

?>