<?php
session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}

	include("connect.php");
	
	date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d');
	
	$sendemail1="";
	$sendemail2="";
	$sendemail3="";
	$sendemail4="";
	
	$email1=$_POST['email1'];
	$courseid=$_POST['courseid'];
	$email2=$_POST['email2'];
	$coursename=$_POST['coursename'];
	$cmduration=$_POST['cmduration'];
	$cmfees=$_POST['cmfees'];
	$cmeligibility=$_POST['cmeligibility'];
	$cmdocument=$_POST['cmdocument'];
	$sendemail1=$_POST['sendemail1'];
	$sendemail2=$_POST['sendemail2'];
	$sendemail3=$_POST['sendemail3'];
	$sendemail4=$_POST['sendemail4'];
	
	if($sendemail1=='Yes')
	{
		if(empty($_FILES['file1']['name']) == false  )
		{
			$filename1 = date("YmdHis").str_replace(' ', '', $_FILES['file1']['name']);
			$path = "download";
			move_uploaded_file( $_FILES['file1']['tmp_name'], $path ."/". $filename1 );
		}
		
	}
	else
	{
		$filename1="";
	}
	if($sendemail2=='Yes')
	{
		if(empty($_FILES['file2']['name']) == false  )
		{
			$filename2 = date("YmdHis").str_replace(' ', '', $_FILES['file2']['name']);
			$path = "download";
			move_uploaded_file( $_FILES['file2']['tmp_name'], $path ."/". $filename2 );
		}
		
	}
	else
	{
		$filename2="";
	}
	if($sendemail3=='Yes')
	{
		if(empty($_FILES['file3']['name']) == false  )
		{
			$filename3 = date("YmdHis").str_replace(' ', '', $_FILES['file3']['name']);
			$path = "download";
			move_uploaded_file( $_FILES['file3']['tmp_name'], $path ."/". $filename3 );
		}
		
	}
	else
	{
		$filename3="";
	}
	if($sendemail4=='Yes')
	{
		if(empty($_FILES['file4']['name']) == false  )
		{
			$filename4 = date("YmdHis").str_replace(' ', '', $_FILES['file4']['name']);
			$path = "download";
			move_uploaded_file( $_FILES['file4']['tmp_name'], $path ."/". $filename4 );
		}
		
	}
	else
	{
		$filename4="";
	}	
	
		
			$eve1 = "select * from res_emailacc_master LIMIT 0,1";
			$re1 = mysqli_query($conn, $eve1);
			
			if(mysqli_num_rows($re1) > 0)
			{
				while($rt1 = mysqli_fetch_assoc($re1))
				{
					
					
					$providername=$rt1['providername'];
					$email=$rt1['email'];
					$epassword=$rt1['epassword'];
					$esmtp=$rt1['esmtp'];
					$eport=$rt1['eport'];
					$essltls=$rt1['essltls'];
					
					
					$uu = "$email";
					$pp = "$epassword";
					$email1="at.saurabh18@gmail.com";
					$subject="couese Detail";
					ob_start();

					$newmessage="<br><br>Course Name: $coursename <br>Duration: $cmduration <br>Price: $cmfees<br>Eligibility: $cmeligibility<br>Document: $cmdocument<br>";;
					
					require_once('class.phpmailer.php');
					
					$mail = new PHPMailer();
					$mail->IsSMTP();
					$mail->CharSet="UTF-8";
					$mail->SMTPSecure = "$essltls";
					$mail->Host = "$esmtp";
					$mail->Port = "$eport";
					$mail->Username = $uu;
					$mail->Password = $epassword;
					$mail->SMTPAuth = true;

					$mail->From = $uu;
					$mail->FromName = "$providername";
					$mail->AddAddress($email1);
					
					
					
					if($filename1=='')
					{}
					else
					{
						$attachmentUrl1 = "https://dummyproject.co.in/lavisa/download/$filename1";
						$tempFile1 = tempnam(sys_get_temp_dir(), "$filename1");  
						file_put_contents($tempFile1, $attachmentUrl1);
						//$mail->AddAttachment($tempFile1);
						$mail->addStringAttachment(file_get_contents($attachmentUrl1), "$filename1");
					}
					if($filename2=='')
					{}
					else
					{
						$attachmentUrl2 = "https://dummyproject.co.in/lavisa/download/$filename2";
						$tempFile2 = tempnam(sys_get_temp_dir(), "$filename2");  
						file_put_contents($tempFile2, $attachmentUrl2);
						//$mail->AddAttachment($tempFile1);
						$mail->addStringAttachment(file_get_contents($attachmentUrl2), "$filename2");
					}	
					
					if($filename3=='')
					{}
					else
					{
						$attachmentUrl3 = "https://dummyproject.co.in/lavisa/download/$filename3";
						$tempFile3 = tempnam(sys_get_temp_dir(), "$filename3");  
						file_put_contents($tempFile3, $attachmentUrl3);
						//$mail->AddAttachment($tempFile1);
						$mail->addStringAttachment(file_get_contents($attachmentUrl3), "$filename3");
					}	
					if($filename4=='')
					{}
					else
					{
						$attachmentUrl4 = "https://dummyproject.co.in/lavisa/download/$filename4";
						$tempFile4 = tempnam(sys_get_temp_dir(), "$filename4");  
						file_put_contents($tempFile4, $attachmentUrl4);
						//$mail->AddAttachment($tempFile1);
						$mail->addStringAttachment(file_get_contents($attachmentUrl4), "$filename4");
					}	
					
					
					$mail->IsHTML(true);
					$mail->Subject    = "$subject";
					$mail->AltBody    = ".";
					$mail->Body    = $newmessage.".";


					if(!$mail->Send())
					{
						
						$err=$mail->ErrorInfo;
						//echo $err;
						//return;
					}
					else
					{		
						
					}	
				}
			}
?>