<?php
//ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
ob_start();
$values = $_REQUEST;
//echo "<pre>";
//print_r($values);
//exit;
$name = $values['name'];
$employee_name = $values['employee_name'];
$email = $values['email'];
//$phone_no = $values['phone_no'];
$country = $values['country'];
$formtype = $values['formtype'];

if($formtype == 'client'){
$compt = "Client  Competition";
}
else if($formtype == 'employee')
{
$compt = "Employee  Competition";
}
else{
$compt = "Both  Competitions";
}
$employeesection ='';
//require("fpdf/fpdf.php");

//include("MPDF56/mpdf.php");
include("smtpmail/classes/class.phpmailer.php");
 
//$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0); 
 
//$mpdf->SetDisplayMode('fullpage');
 
//$mpdf->list_indent_first_level = 0;  // 1 or 0 - whether to indent the first level of a list
$template = file_get_contents('new_emailer.html'); 
$template = preg_replace("{{compt}}",$compt,$template);
if($formtype == 'employee'){
$employeesection = '<div class="section1">
<div class="left_area"> Client Name :</div>
<div class="right_area"> '.$name.'</div>
</div>';
$employeesection .= '<div class="section1">
<div class="left_area"> Employee Name :</div>
<div class="right_area"> '.$employee_name.'</div>
</div>';
}
if($formtype == 'client'){
$employeesection = '<div class="section1">
<div class="left_area"> Client Name :</div>
<div class="right_area"> '.$name.'</div>
</div>';
}
if($formtype == 'both'){
$employeesection = '<div class="section1">
<div class="left_area"> Client Name :</div>
<div class="right_area"> '.$name.'</div>
</div>';
$employeesection .= '<div class="section1">
<div class="left_area"> Employee Name :</div>
<div class="right_area"> '.$country.'</div>
</div>';

}
//$template = preg_replace("{{employeesection}}",$employeesection,$template);
//$template = preg_replace("{{email}}",$email,$template);
//$template = preg_replace("{{phone}}",$phone_no,$template);
//$template = preg_replace("{{country}}",$country,$template);

//echo $template; exit;

//$mpdf->WriteHTML(utf8_encode($template));
//$pdfdoc = $mpdf->Output();
//exit;
// email stuff (change data below)
// change this email address to VE's email ID
//$ve_id = 'sales@virtualemployee.com';
$ve_id = 'hr@virtualemployee.com';
$to = $email;
$from = 'sales@virtualemployee.com';
$subject = "Thank You for your participation!";
//$message = "<p>Please see the attachment.</p>";
//$message = "Hello,<p>Thank you for your participation in VirtualEmployee.com competitions. Please find attached the 'guidelines and terms & conditions' booklet for your reference.</p><p>Please contact us in case of any query or if you require any assistance.</p><p>US - (+1) 877 697 8006</br>UK - (+44) 203 478 5941</br>AU - (+61) 280 733 418</br>IN - (+91) 120 662 8500</br>CA - (+1) 416 915 8941</p><p>Best Regards,</p><p>Virtual Employee Team</p>";

$message = "Dear " . $name . ",<p>Thank you for signing up...</p><p>As the next step, shoot a video about your Virtual Employee and share it with us via:<br/><br/>
Dropbox: (Save the video in your dropbox folder and share the link with us.)<br/>
Email: hr@virtualemployee.com, sales@virtualemployee.com</p><table width='700' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td bgcolor='#8ECCF0'>
<table width='700' border='0' cellpadding='3' cellspacing='1' style='font:12px Arial, Helvetica, sans-serif;'>
<tr>
<td colspan='2' align='center' bgcolor='#e2e4f0' style='font-weight:bold; font-size:14px; line-height:21px;'>General Information</td>
</tr>
<tr>
<td bgcolor='#E0F0F8'><strong>Your Name:</strong></td>
<td bgcolor='#E0F0F8'> . $name . </td>
</tr>
<tr>
<td bgcolor='#E0F0F8'><strong>Employee Name:</strong></td>
<td bgcolor='#E0F0F8'> . $employee_name . </td>
</tr>
<tr>
<td bgcolor='#E0F0F8'><strong>Email Address:</strong></td>
<td bgcolor='#E0F0F8'> . $email . </td>
</tr>
<tr>
<td bgcolor='#E0F0F8'><strong>Country:</strong></td>
<td bgcolor='#E0F0F8'> . $country . </td>
</tr>
</table>
</td>
</tr>
</table><p>Feel free to reach out to us in case of any query.</p><p>US - (+1) 772 222 3505<br>UK - (+44) 169 188 7766<br>AU - (+61) 280 733 418<br>CA - (+1) 416 915 8941<br><br>Email - hr@virtualemployee.com, sales@virtualemployee.com</p><p>Best Regards,<br>Virtual Employee Team</p>";
// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = ucwords($name)."-VE-Competitions.pdf";

// encode data (puts attachment in proper format)
//$pdfdoc = $mpdf->Output('', 'S');
//$attachment = chunk_split(base64_encode($pdfdoc));
//file_put_contents($filename,$pdfdoc);
//$filename2 = 'Competition-Guideline-Term-&-Conditions.pdf';
//$attachment2 = chunk_split(base64_encode($filename2));


$SmtpServer = 'smtp.gmail.com'; 
$SmtpPort	= '465'; 
$SmtpSecure	= 'ssl'; 
$SmtpUser	= 'vecompetition2@gmail.com'; 
$SmtpPass	= 'pass@12345'; 
$SmtpUse	= FALSE;


$mail = new PHPMailer();
if($SmtpUse) {
	$mail->IsSMTP(); // telling the class to use SMTP
	$mail->Host       = $SmtpServer;  // SMTP server
	$mail->SMTPAuth   = true;         // enable SMTP authentication
	$mail->Host       = $SmtpServer;  // sets the SMTP server
	$mail->Port       = $SmtpPort;    // set the SMTP port for the GMAIL server
	$mail->Username   = $SmtpUser;    // SMTP account username
	$mail->Password   = $SmtpPass;    // SMTP account password
	$mail->SMTPSecure = $SmtpSecure;
 }
 
$mail->AddReplyTo($ve_id);
$mail->setFrom($from);
$mail->addAddress($to);
//$mail->addattachment($filename); //Attach a file here
//$mail->addattachment($filename2); //Attach a file here
$mail->Subject=$subject;
$mail->MsgHTML($message); //Put your body of the message you can place html code here
//send the message, check for errors
$mail->IsHTML(true);

$mail2 = new PHPMailer();
if($SmtpUse) {
	$mail2->IsSMTP(); // telling the class to use SMTP
	$mail2->Host       = $SmtpServer;  // SMTP server
	$mail2->SMTPAuth   = true;         // enable SMTP authentication
	$mail2->Host       = $SmtpServer;  // sets the SMTP server
	$mail2->Port       = $SmtpPort;    // set the SMTP port for the GMAIL server
	$mail2->Username   = $SmtpUser;    // SMTP account username
	$mail2->Password   = $SmtpPass;    // SMTP account password
	$mail2->SMTPSecure = $SmtpSecure;
}
$mail2->AddReplyTo($from);
$mail2->setFrom($from);
$mail2->addAddress($ve_id);
$mail2->addattachment($filename); //Attach a file here
$mail2->Subject=$subject;
$mail2->MsgHTML($message); //Put your body of the message you can place html code here
//send the message, check for errors
$mail2->IsHTML(true);

if (!$mail->send() || !$mail2->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "SENDING";
}
//unlink(ucwords($name)."-VE-Competitions.pdf");
header("location:awards-thank-you");
?>
