<?php require_once("panel/system/ayar.php"); ?>
<?php require_once("panel/system/fonksiyon.php"); ?>
<?php
	$mailayar = Sonuc(Sorgu("SELECT * FROM mail WHERE id ='1'"));
	$mailayar = json_decode($mailayar->bilgiler,true);
	$adiniz		= p('your_name');
	$email		= p('your_mail');
	$aadi		= p('friend_name');
	$aemail		= p('friend_mail');
	$urunadi	= p('urunadi');
	$urunlink	= p('urunlink');
	$url		= p('url');
	$konu 		= "Arkadaşınız size bir ürün önerdi.";
	$mesaj 		= "
		<div>
				
			<p>Sayın $aadi,</p>
			
			<p>Arkadaşınız $adiniz size incelemeniz için $ayar->firma_adi de bulunan ".$urunadi." ürününü tavsiye etti.</p>
			
			<p>Ürün hakkında detaylı bilgi almak için <a href='$urunlink'> BURAYI TIKLAYINIZ </a>.</p>
			
			<p>$ayar->firma_adi</br> $url</p>
		
		</div>" ;
		if(empty($adiniz) || empty($email) || empty($aadi) || empty($aemail)){
				echo '<div class="alert alert-danger" style="background:#f7a632;color:#FFF;">
				<button type="button" class="close" data-dismiss="alert">×</button>
				<strong style="float:left;margin-right:5px;"><i style="margin-top:5px;font-size:25px;" class="fa fa-exclamation-triangle"></i></strong> 
				<strong>İşlem Başarısız </strong><br> 
				Gerekli alanları doldurunuz.
			</div>';
		}else{
		require("class.phpmailer.php");
		$mail = new PHPMailer();
		$mail->IsSMTP();
		$mail->SMTPDebug = 1;
		$mail->SMTPAuth = true;
		$mail->Host = "".$mailayar['mail_host']."";
		$mail->Port = 587; 
		$mail->IsHTML(true);
		$mail->SetLanguage("tr", "phpmailer/language");
		$mail->CharSet  ="utf-8";
		$mail->Username = "".$mailayar['mail_username']."";
		$mail->Password = "".$mailayar['mail_parola']."";
		$mail->SetFrom("".$mailayar['mail_username']."", "$ayar->firma_adi");
		$mail->AddAddress($aemail); 
		$mail->Subject = $konu;
		$mail->Body = $mesaj;
		if(!$mail->Send()){
				echo '<div class="alert alert-danger" style="background:#f7a632;color:#FFF;">
				<button type="button" class="close" data-dismiss="alert">×</button>
				<strong style="float:left;margin-right:5px;"><i style="margin-top:5px;font-size:25px;" class="fa fa-exclamation-triangle"></i></strong> 
				<strong>İşlem Başarısız </strong><br> '.$mail->ErrorInfo.'</div>';
			} else {
				echo '<div class="alert alert-success" style="background:#73B572;color:#FFF;">
					<button type="button" class="close" data-dismiss="alert">×</button>
					<strong style="float:left;margin-right:5px;"><i style="margin-top:5px;font-size:25px;" class="fa fa-smile-o"></i></strong> 
					<strong>İşlem Tamamlandı. </strong><br> 
					Tavsiyeniz Gönderildi !
				</div>';
				echo '<script type="text/javascript">';
				echo 'setTimeout(function() { window.location="'.$urunlink.'"}, 1500);';
				echo '</script>';
			}	
		}
	?>