File: /home/imensosw/lp.imensosoftware.com/contact_popup_form_submit.php
<?php
require('vendor/autoload.php'); // Load the SendGrid library
use SendGrid\Mail\Mail;
//use Swift_SmtpTransport;
//use Swift_Mailer;
//use Swift_Message;
ini_set('display_errors', 1);
error_reporting(E_ALL);
$thankyoupage = 'https://www.imensosoftware.com/thank-you';
$return_array = array('msg'=>'', 'redirect_to' => $thankyoupage, 'status' => 'success');
$msg = '';
if(isset($_POST["contact_name"])):
$contact_name = trim($_POST["contact_name"]);
$contact_email = trim($_POST["contact_email"]);
$contact_phone_full = trim($_POST["contact_phone_full"]);
$contact_country = trim($_POST["contact_country"]);
$contact_ip = trim($_POST["contact_ip"]);
$lead_from_page = trim($_POST["lead_from_page"]);
if ( empty( $contact_name ) ) {
$return_array['contact_name_error'] = "Please complete this required field";
$return_array['status'] = 'error';
}
if ( empty( $contact_phone_full )) {
$return_array['contact_phone_error'] = "Please complete this required field";
$return_array['status'] = 'error';
}
if ( empty( $contact_email ) ) {
//$return_array['contact_email_error'] = "Please complete this required field";
//$return_array['status'] = 'error';
}
if ( !empty( $contact_email ) ) {
$secure_check = sanitize_my_email($contact_email);
if ($secure_check == false) {
$return_array['contact_email_error'] = "Please add valid email address!";
$return_array['status'] = 'error';
}
}
$res = verifyReCaptchaV3();
if(!$res['success'] == true){
//$return_array['g_recaptcha_response_error'] = "There is some error. Please reload page and try again!";
//$return_array['status'] = 'error';
}
if($return_array['status'] == 'error'){
echo json_encode($return_array);
exit();
}
// This is the email where you want to send the comments.
//$to = 'jparihar@imensosoftware.com';
$to_cc= 'dkag@imenso.tech';
//$to = 'jim@imensosoftware.com,jparihar@imensosoftware.com';
$to_bcc = 'rahul.imenso@gmail.com';
$to = 'jim@imensosoftware.com';
//$from_name = $_POST['contact_name'].' '.$_POST['last_name'];
$from_name = $contact_name;
$from_email = $contact_email;
// Your message subject.
$body = '<html><body>';
$subject = $lead_from_page = "Request a Call - ".$lead_from_page;
$body .='<table>';
$body .='<tr><td style="width:130px;"><strong>From:</strong></td><td>'.$contact_name.'</td></tr>';
$body .='<tr><td><strong>Contact Number:</strong></td><td>'.$contact_phone_full.'</td></tr>';
$body .='<tr><td><strong>Email:</strong></td><td>'.$contact_email.'</td></tr>';
$body .='<tr><td><strong>Country:</strong></td><td>'.$contact_country.'</td></tr>';
$body .='<tr><td><strong>IP:</strong></td><td>'.$contact_ip.'</td></tr>';
if(!empty($lead_from_page)){
$body .='<tr><td><strong>Page:</strong></td><td>'.$lead_from_page.'</td></tr>';
}
$body .='</table></body></html>';
$send_using = 'info@imensosoftware.com';
// declare variable
/*
$headers = 'Reply-To: '.$from_name.' <'.$from_email.'>' . "\r\n";
// add more info
$headers .= "Return-Path: '.$send_using.'\r\n";
$headers .= 'From: '.$subject.' <'.$send_using.'>' . "\r\n";
$headers .= "Organization: Imenso Software\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
//$headers .= "CC: ".$to_cc."\r\n";
//$headers .= "BCC: ".$to_bcc."\r\n";
$mail = mail( $to, $subject, $body, $headers );
if($mail){$return_array['mail_status'] = $mail; $return_array['to'] = $to;}
*/
//Send mail using SMTP Start
try{
// Now you can use SendGrid classes
//use SendGrid\Mail\Mail;
// Create a SendGrid object
$sendgrid = new \SendGrid('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');
//$sendgrid = new \SendGrid('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');
// Create a new email
if(!empty($from_email)){
$from_email = filter_var($from_email, FILTER_SANITIZE_EMAIL);
}else{
$from_email = $send_using;
}
$email = new Mail();
//$email->setFrom("info@imensosoftware.com", $subject);
$email->setFrom($send_using, 'Imenso Software');
$email->setSubject($subject);
$email->addTo($to, 'Imenso Software');
$email->addContent("text/html", $body);
$email->setReplyTo($from_email, $from_name);
// Send the email
$mail = 0;
$response = $sendgrid->send($email);
if ($response->statusCode() === 202) {
$mail = 1;
$return_array['mail_status'] = $mail; $return_array['to'] = $to;
}else{
$return_array['mail_status'] = $mail; $return_array['to'] = $to;
}
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
//Send mail using SMTP End
$return_array['msg'] = "Submitted Successfully!";
$return_array['status'] = 'success';
echo json_encode($return_array);
else:
echo json_encode($return_array);
endif;
function sanitize_my_email($email) {
$field = filter_var($email, FILTER_SANITIZE_EMAIL);
$pattern = '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';
$return = false;
if (preg_match($pattern, $email) && filter_var($field, FILTER_VALIDATE_EMAIL)) {
$return = true;
} else {
$return = false;
}
return $return;
}
function verifyReCaptchaV3(){
$site_verify_url = "https://www.google.com/recaptcha/api/siteverify";
$data = [
'secret' => '6LcOMP4mAAAAAAw_hKfF2Y-pTLuaD6BGGRQIdeh7',
'response' => $_POST['g_recaptcha_response'],
// 'remoteip' => $_SERVER['REMOTE_ADDR']
];
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$response = file_get_contents($site_verify_url, false, $context);
$res = json_decode($response, true);
return $res;
}
?>