<?php 

    session_start(); 
	
	// Enter your Name here!
	$yourname = "Your Name";
	
	// Enter your Email Address here!
	$youremail = "example@example.com";
	
	// Enter your Desired Email Subject!
	$mailsubject = "Message from your Support Form";
	
	$firstname = strip_tags(trim($_POST["firstname"]));
	$lastname = strip_tags(trim($_POST["lastname"]));	
	$useremail = strip_tags(trim($_POST["useremail"]));
	$usersubject = strip_tags(trim($_POST["usersubject"]));
	$usermessage = strip_tags(trim($_POST["usermessage"]));
    $verification = strip_tags(trim($_POST["verification"]));
	
    $random_file1 = uniqid();
    $random_file2 = uniqid();
	$random_file3 = uniqid();
    $finalname1 = $random_file1.$_FILES['userfile1']['name'];
    $finalname2 = $random_file2.$_FILES['userfile2']['name'];
    $finalname3 = $random_file3.$_FILES['userfile3']['name'];
		
    if ($_FILES['userfile1']['error'] == 0 || $_FILES['userfile2']['error'] == 0 || $_FILES['userfile3']['error'] == 0) {
		move_uploaded_file($_FILES['userfile1']['tmp_name'], '../upload/' .$finalname1);
		move_uploaded_file($_FILES['userfile2']['tmp_name'], '../upload/' .$finalname2);
	    move_uploaded_file($_FILES['userfile3']['tmp_name'], '../upload/' .$finalname3);
 
    require "class.autoload.php";
    require "message.php";
		
    $mail = new PHPMailer();
	$mail->isSendmail();
	$mail->IsHTML(true);
	$mail->From = $useremail;
	$mail->CharSet = "UTF-8";
	$mail->FromName = $firstname . $lastname;
	$mail->Encoding = "base64";
	$mail->Timeout = 200;
	$mail->ContentType = "text/html";
	$mail->addAddress($youremail, $yourname);
	$mail->Subject = $mailsubject;
	$mail->AddAttachment('../upload/'.$finalname1);
    $mail->AddAttachment('../upload/'.$finalname2);
	$mail->AddAttachment('../upload/'.$finalname3);		
	$mail->Body = $message;
	$mail->AltBody = "To view this message, please use an HTML compatible email";
			
	// Use this if you want more that one user receive a email from contact form ... Just turn True or False!
	$recipients = false;
	if($recipients == true){
		$recipients = array(
			"example@example.com" => "Person Name",
			"example@example.com" => "Person Name",
		);
		
		foreach($recipients as $email => $name){
			$mail->AddBCC($email, $name);
		}	
	}
		
	if($mail->Send()) {
		
		require "automessage.php";
			
		$automail = new PHPMailer();
		$automail->isSendmail();
        $automail->From = $youremail;
        $automail->FromName = $yourname;
	    $automail->isHTML(true);                                 
		$automail->CharSet = "UTF-8";
		$automail->Encoding = "base64";
		$automail->Timeout = 200;
		$automail->ContentType = "text/html";
        $automail->AddAddress($useremail, $firstname . $lastname);
        $automail->Subject = "We received your ticket from our Support form";
        $automail->Body = $automessage;
		$automail->AltBody = "To view this message, please use an HTML compatible email";
      
        if($automail->Send()){
			// Email has sent successfully.
			echo '<div class="contact-success-message">Congratulations! Your Message has been Send</div>';
        }
	    else {
			// Email have an Error.	
			echo '<div class="contact-error-message">Attention! There is an Error</div>';
		}
    } 
}
  
?>