<?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']);
$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 New lead sales Enquiry | ";
$lp_name = " $subject_text | B. U. Bhandari Motors New lead sales Enquiry";
//$lp_link = "https://akshayamotors.co.in/$url_name_text";

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.="Contact Us Form";
}
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>Selected Model  </strong> </td><td style='border:1px solid #666;border-collapse:collapse;'>" . trim($course) . "</td></tr>";
$message .= $comment;
/*$message .= $date;*/
$message .= "</table>";
$message .= "</body></html>";

$body = $message;

$from = new Email("B. U. Bhandari Motors Private Limited Enquiry", "innoserv-dm@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);

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

$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, "aniruddha.bhagwat@bubhandari.in");
$mail->personalization[0]->addCC($cc);

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

$cc = new Email(null, "achala.bhushan@innoserv.co.in");
$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);

}

 ?>
