<?PHP namespace SendGrid; ?>

<?php
require_once('sendgrid-php/sendgrid-php.php');

$formname = urldecode($_POST['formname']);
$formtitle = urldecode($_POST['formtitle']);
$name = urldecode($_POST['name']);
$mobile = urldecode($_POST['mobile']);
$email = urldecode($_POST['email']);
$city = urldecode($_POST['city']);
$modelowned = urldecode($_POST['modelowned']);
/*$regno = urldecode($_POST['regno']);
$vin = urldecode($_POST['vin']);*/
$course = urldecode($_POST['course']);
$comment = urldecode($_POST['comment']);

$actual_link= urldecode($_POST['actual_link']);
$url_name_text = (urldecode($_POST['urlname']));
$subject_text = ucfirst($url_name_text);
/*$subject_text = substr($url_name_text, 0, strpos($url_name_text, "."));*/

/*echo "url" .$_POST['urlname'];
echo "sub" .$subject_text;*/

if($name != '' && $mobile != '' && $email != '' && $city != '') {

$subject = " $subject_text | B. U. Bhandari Motors | Spin the Wheel Enquiry | New lead | ";
$lp_name = " $subject_text | B. U. Bhandari Motors | Spin the Wheel Enquiry | New lead ";

if($formname == "sticky-form")
{
    $subject.="Sticky Form";
}
else if($formname == "top-form")
{
    $subject.="Enquire Now Form";
}
else if($formname == "enquire-form")
{
    $subject.="Enquire Now Form";
}
else if($formname == "download-form")
{
    $subject.="Get More Information Form";
}
else if($formname == "contact-form")
{    
    $subject.="Claim the Prize Form";
    
    $course ="<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>Prize Won</strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($course) . "</td></tr>";
}
else if($formname == "query-form")
{    
    $comment ="<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>Query</strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($comment) . "</td></tr>";
    
    $subject.="Query Form";
}

/*if($formtitle == "GLA")
{
    $subject.="Download Brochure - GLA Form";
}

else if($formtitle == "GLC")
{
    $subject.="Download Brochure - GLC Form";
}

else if($formtitle == "C-Class")
{
    $subject.="Download Brochure - C-Class Form";
}

else if($formtitle == "E-Class")
{
    $subject.="Download Brochure - E-Class Form";
}

else if($formtitle == "S-Class")
{
    $subject.="Download Brochure - S-Class Form";
}

else if($formtitle == "V-Class")
{
    $subject.="Download Brochure - V-Class Form";
}

else if($formtitle == "GLE")
{
    $subject.="Download Brochure - GLE Form";
}

else if($formtitle == "GLS")
{
    $subject.="Download Brochure - GLS Form";
}
*/

$message = '<html><body>';
$message .= '<table rules="all" style="border:1px solid #666;" cellpadding="10">';
$message .= "<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>Name </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($name) . "</td></tr>";
$message .= "<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>Contact </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($mobile) . "</td></tr>";
$message .= "<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>Email Id </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($email) . "</td></tr>";
$message .= "<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>City  </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($city) . "</td></tr>";
$message .= "<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>MB Model Owned  </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($modelowned) . "</td></tr>";
//$message .= "<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>Reg No.  </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($regno) . "</td></tr>";
//$message .= "<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>VIN No.  </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($vin) . "</td></tr>";
//$message .= "<tr><td style='border:1px solid #666;border-collapse:collapse;'><strong>Selected Model  </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($course) . "</td></tr>";
$message .= $course;
$message .= $comment;
/*$message .= $date;*/
$message .= "</table>";
$message .= "</body></html>";

$body = $message;

$from = new Email("B. U. Bhandari Motors - Spin the Wheel Enquiry - New lead", "innoservdm@BUBhandari.co.in");
$subject = $subject;

/*$to = new Email(null, "suraj.bhopi@innoserv.co.in");
$content = new Content("text/html", "$body");
$mail = new Mail($from, $subject, $to, $content);*/

/*
$cc = new Email(null, "sushant.vanarse@innoserv.co.in");
$mail->personalization[0]->addCC($cc);*/


$to = new Email(null, "sneha.tambe@bubhandari.in");
$content = new Content("text/html", "$body");
$mail = new Mail($from, $subject, $to, $content);

$cc = new Email(null, "ritika@innoserv.co.in");
$mail->personalization[0]->addCC($cc);

$cc = new Email(null, "shirish.deshpande@innoserv.co.in");
$mail->personalization[0]->addCC($cc);

$cc = new Email(null, "vishal@innoserv.co.in");
$mail->personalization[0]->addCC($cc);

$cc = new Email(null, "sushant.vanarse@innoserv.co.in");
$mail->personalization[0]->addCC($cc);

$cc = new Email(null, "shubham.lagade@innoserv.co.in");
$mail->personalization[0]->addCC($cc);

$cc = new Email(null, "achala.bhushan@innoserv.co.in");
$mail->personalization[0]->addCC($cc);

/*$cc = new Email(null, "abhilasha.naik@bubhandari.in");
$mail->personalization[0]->addCC($cc);*/

$cc = new Email(null, "akshay.p@fmadigital.com");
$mail->personalization[0]->addCC($cc);


$apiKey = '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';
$sg = new \SendGrid($apiKey);

$request_body = $mail;
$response = $sg->client->mail()->send()->post($request_body);

}

 ?>
