<?PHP namespace SendGrid; ?>

<?php
require 'sendgrid-php/vendor/autoload.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']);
$course = urldecode($_POST['course']);
/*$vin = urldecode($_POST['vin']);*/

/*$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 Pvt Ltd - After Sales Enquiry | ";
$lp_name = " $subject_text | B. U. Bhandari Motors Pvt Ltd - After 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>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>Enquiry For  </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;


$apiKey = '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';
$email = new \SendGrid\Mail\Mail();
$email->setFrom("leadbubhandari@gmail.com", "");
$email->setSubject("$subject");
$email->addTo("sneha.tambe@bubhandari.in", "");
$email->addCc('shirish.deshpande@innoserv.co.in');
$email->addCc('irshad.kazi@innoserv.co.in');
$email->addCc('vishal@innoserv.co.in');
$email->addCc('sushant.vanarse@innoserv.co.in');
$email->addCc('aditya.jathar@innoserv.co.in');
$email->addCc('atul.goel@innoserv.co.in'); 
$email->addContent("text/html", "$message");

$sendgrid = new \SendGrid($apiKey);

$response = $sendgrid->send($email);

}
?>
