MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/lp.imensosoftware.com/contact_form_submit_bk.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["first_name"])):
    $first_name = trim($_POST["first_name"]);
    $company_phone = trim($_POST["company_phone"]);
    $company_email = trim($_POST["company_email"]);
    $company_name = trim($_POST["company_name"]);
    $req_text = trim($_POST["req_text"]);
    $company_phone_full = trim($_POST["company_phone_full"]);
    $company_phone = trim($_POST["company_phone"]);
    
    $country_code = trim($_POST["country_code"]);
    $user_ip = trim($_POST["user_ip"]);
    $lead_from_page = trim($_POST["lead_from_page"]);

    $escapedContent = htmlspecialchars($req_text, ENT_QUOTES, 'UTF-8');
    $req_text = nl2br($escapedContent);
    
    if ( empty( $first_name ) ) {
        $return_array['first_name_error'] = "Please complete this required field";
        $return_array['status'] = 'error';
    }
    
    if ( empty( $company_phone ) ||  empty( $company_phone_full )) {
        $return_array['company_phone_error'] = "Please complete this required field";
        $return_array['status'] = 'error';
    }else{
        // Validate phone number
        /*$phone_number_validation_regex = "/^\\+?\\d{1,4}?[-.\\s]?\\(?\\d{1,3}?\\)?[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,9}$/";
        $validate_phone = preg_match($phone_number_validation_regex, $_POST["company_phone"]); // returns 1
        if(!$validate_phone){
            $return_array['company_phone_error'] = "Invalid Contact Number";
            $return_array['status'] = 'error';    
        }*/
    }
    /*if ( empty( $_POST["last_name"] ) ) {
        $return_array['last_name_error'] = "Please complete this required field";
        $return_array['status'] = 'error';
    }*/
    
    if ( empty( $company_email ) ) {
        $return_array['company_email_error'] = "Please complete this required field";
        $return_array['status'] = 'error';
    }
    
    if ( empty( $company_name ) ) {
        $return_array['company_name_error'] = "Please complete this required field";
        $return_array['status'] = 'error';
    }
    /*if ( empty( $_POST["lead_country"] ) ) {
        $return_array['lead_country_error'] = "Please complete this required field";
        $return_array['status'] = 'error';
    }*/
    if ( empty( $req_text ) ) {
        $return_array['req_text_error'] = "Please complete this required field";
        $return_array['status'] = 'error';
    }
    if ( !empty( $company_email ) ) {
        $secure_check = sanitize_my_email($company_email);
        if ($secure_check == false) {
            $return_array['company_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= 'rjoshi@imenso.tech';
    //$to = 'jim@imensosoftware.com,jparihar@imensosoftware.com';
    $to_bcc = 'rahul.imenso@gmail.com';
    $to = 'jim@imensosoftware.com';
    //$from_name = $_POST['first_name'].' '.$_POST['last_name'];
    $from_name = $first_name;
    $from_email = $company_email;
 
    // Your message subject.
    $body = '';
    $subject = $lead_from_page;
    $body .='<table>';
    $body .='<tr><td style="width:130px;"><strong>From:</strong></td><td>'.$first_name.'</td></tr>';
    $body .='<tr><td><strong>Company Name:</strong></td><td>'.$company_name.'</td></tr>';
    $body .='<tr><td><strong>Contact Number:</strong></td><td>'.$company_phone_full.'</td></tr>';
    $body .='<tr><td><strong>Email:</strong></td><td>'.$company_email.'</td></tr>';
    $body .='<tr><td><strong>Country:</strong></td><td>'.$country_code.'</td></tr>';
    $body .='<tr><td><strong>IP:</strong></td><td>'.$user_ip.'</td></tr>';
    if(isset($_POST['lead_from_page']) && !empty($lead_from_page)){
        $body .='<tr><td><strong>Page:</strong></td><td>'.$lead_from_page.'</td></tr>';
    }
    $body .='<tr><td colspan="2"><p style="margin-top:0px; margin-bottom:5px;"><strong>Requirement:</strong></p>'.$req_text.'</td></tr>';
    
    $body .='</table>';
    // This are the message headers.
    // You can learn more about them here: https://developer.wordpress.org/reference/functions/wp_mail/
    

    /*$headers = array(
        'Content-type' =>'Content-Type: text/html; charset=UTF-8',
        'From' => 'From: '.$from_name.' <'.$from_email.'>',
        'Reply-To' => 'Reply-To: '.$from_name.' <'.$from_email.'>',
        'X-Mailer' => 'PHP/' . phpversion()
    );*/


    /*$headers = array(
        'Content-Type: text/html; charset=UTF-8',
        'From: '.$from_name.' <'.$from_email.'>',
        'Reply-To: '.$from_name.' <'.$from_email.'>',
        'X-Mailer: PHP/' . phpversion()
    );*/
    $send_using = 'info@imensosoftware.com';
    
    
    $headers = 'From: '.$subject.' <'.$send_using.'>' . "\r\n";
    $headers .= 'Reply-To: '.$from_name.' <'.$from_email.'>' . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
    //$headers .= 'X-Mailer: PHP/'. phpversion() . "\r\n";


    // 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";
       
      // Create email headers
    /*$headers .= 'From: '.$first_name."<".$from.">\r\n".
    // $headers .= 'From: '.$name.'<'.$from.'>\r\n'. 
          'Reply-To: '.$from."\r\n" .
          'X-Mailer: PHP/' . phpversion();
       */
    
    //$headers = array('Content-Type: text/html; charset=UTF-8');
     // Change the From address.
    /*add_filter( 'wp_mail_from', function ( $original_email_address ) {
        //return $_POST['company_email'];
        return 'info@imensosoftware.com';
    } );*/
    // Change the From name.
    /*add_filter( 'wp_mail_from_name', function ( $original_email_from ) {
        //return $_POST['first_name'].' '.$_POST['last_name'];
        return $_POST['first_name'];
    } );*/

    //$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
        $from_email = filter_var($from_email, FILTER_SANITIZE_EMAIL);
        $email = new Mail();
        //$email->setFrom("info@imensosoftware.com", $subject);
        $email->setFrom("info@imensosoftware.com", '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;
        }

        //New process
        /*
        // Set up SendGrid SMTP settings
        $smtpUsername = 'apikey';
        $smtpPassword = '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';
        $smtpServer = 'smtp.sendgrid.net';
        $smtpPort = 587; // Set the desired port here

        // Create the SMTP client
        $transport = (new Swift_SmtpTransport($smtpServer, $smtpPort))
            ->setUsername($smtpUsername)
            ->setPassword($smtpPassword);

        // Create the Mailer instance
        $mailer = new Swift_Mailer($transport);

        // Create the message
        $message = (new Swift_Message($subject))
            ->setFrom(['developer@imenso.in' => $subject])
            ->setTo([$to_cc])
            ->setBody($body);

        // Send the email
        $result = $mailer->send($message);

        if ($result) {
            $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;
}
?>