HEX
Server: Apache
System: Linux sg2plzcpnl509433.prod.sin2.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: qhl5pt3kkb1d (10888259)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home/qhl5pt3kkb1d/public_html/tstp-old/free-dsat-mail.php
<?php

$INTERAKT_API_URL = 'https://api.interakt.ai/v1/public/message/';
$INTERAKT_API_KEY = 'bGlLOFFiS1BhZ095bndYM0J3Tzh3MjFCS3dJa05NOWVGYmtIQTJ4X3lSUTo=';


$sender = "info@tstp.in";
$to = "shailendra@tstp.in";
$cc = "brownfox.consultant@gmail.com";
$fixed_phone_number = '7574824766'; //Shailendra garg Owner

date_default_timezone_set('Asia/Kolkata');

header('Content-Type: application/json');

// For File Append Logic
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
    $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    $phone = filter_var($_POST['phone'], FILTER_SANITIZE_STRING);
    $user_captcha = $_POST['popupCaptcha'];
    $stored_captcha = $_POST['popupCaptcha_code'];
    
    if (empty($name)) {
        echo json_encode(['success' => false, 'message' => "Name is required."]);
        exit();
    }

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        echo json_encode(['success' => false, 'message' => "Invalid email address."]);
        exit();
    }

    if (empty($phone) || !preg_match('/^0?\d{10}$/', $phone)) {
        echo json_encode(['success' => false, 'message' => "Phone number must be 10 digits."]);
        exit();
    }
    
    if ($user_captcha != $stored_captcha) {
        echo json_encode(['success' => false, 'code' => "1", 'message' => "Incorrect CAPTCHA."]);
        exit();
    }
    
    $filename = "free-dsat-data.txt";
    $file_contents = file_exists($filename) ? file_get_contents($filename) : '';
    
    $lines = explode("\n", trim($file_contents));
    $last_entry = array_filter($lines, function($line) {
        return preg_match('/^(\d+)\./', $line);
    });
    
    $last_index = 0;
    
    if (!empty($last_entry)) {
        $last_index = (int)preg_replace('/^(\d+)\./', '$1', end($last_entry));
    }
    
    $next_index = $last_index + 1;
    $file_content = "$next_index. Name: $name, Email: $email, Phone: $phone, Date: " . date('Y-m-d H:i:s') . "\n";
    
    if (!file_put_contents($filename, $file_content, FILE_APPEND)) {
        echo json_encode(['success' => false, 'code' => "1", 'message' => "Error saving lead to file."]);
        exit();
    }
    
    
  //Whats up msg send code
    $message_data = [
        "countryCode" => "+91",
        "phoneNumber" => $fixed_phone_number,
        "type" => "Template",
        "callbackData" => "some_callback_data",
        "template" => [
            "name" => "send_message",
            "languageCode" => "en_US",
            "bodyValues" => [
                $name,
                $email,
                $phone
            ]
        ]
    ];
    
    $ch = curl_init($INTERAKT_API_URL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message_data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Basic ' . $INTERAKT_API_KEY,
        'Content-Type: application/json'
    ]);

    $response = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    // For Email Logic
    $curl = curl_init();

    curl_setopt_array($curl, [
        CURLOPT_URL => "https://api.brevo.com/v3/smtp/email",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => json_encode([
            "sender" => [
                "name" => "Info TSTP",
                "email" => $sender
            ],
            "to" => [
                [
                    "name" => "Shailendra Garg",
                    "email" => $to
                ]
            ],
            "cc" => [
                [
                    "name" => "BrownFox",
                    "email" => $cc
                ]
            ],
            'htmlContent' => '<!DOCTYPE html>
            <html lang="en">
                <head>
                    <title>The Smart Test Prep - Experience Better Learning</title>
                </head>
                <body>
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td align="center">
                                    <table class="col-600" width="600" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-left:20px; margin-right:20px;margin-top:20px;">
                                        <tbody>
                                            <tr>
                                                <td align="center" valign="top" style="background-size:cover; background-position:top;height:400">
                                                    <table class="col-600" width="600" height="400" border="0" align="center" cellpadding="0" cellspacing="0">
                                                        <tbody>
                                                            <tr>
                                                                <td align="center" style="line-height: 0px;">
                                                                    <img style="display:block; line-height:0px; font-size:0px; border:0px;" src="https://thesmarttestprep.com/images/logo.png" width="400" height="103" alt="logo">
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td style="font-family: Raleway, sans-serif; font-size:20px; color:#000000; line-height:2px;">
                                                                    Hi,
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td style="font-family: Raleway, sans-serif; font-size:20px; color:#000000;">
                                                                    New lead <b>Free DSAT Test</b> generated from the website.
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td height="20"></td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td align="center">
                                    <table class="col-600" width="600" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-left:20px; margin-right:20px; margin-bottom: 20px;">
                                        <tbody>
                                            <tr>
                                                <td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Name : </b>' . $name . '</td>
                                            </tr>
                                            <tr>
                                                <td height="10"></td>
                                            </tr>
                                            <tr>
                                                <td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Email : </b>' . $email . '</td>
                                            </tr>
                                            <tr>
                                                <td height="10"></td>
                                            </tr>
                                            <tr>
                                                <td style="font-family: Raleway, sans-serif; font-size:18px; color:#000000;"><b>Phone : </b>' . $phone . '</td>
                                            </tr>
                                            <tr>
                                                <td height="10"></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td height="5"></td>
                            </tr>
                        </tbody>
                    </table>
                </body>
            </html>',
            'subject' => 'Free DSAT Test Inquiry From The Smart Test Prep',
        ]),
        CURLOPT_HTTPHEADER => [
            "accept: application/json",
            "api-key: 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",
            "content-type: application/json"
        ],
    ]);

    $response = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);
    
    
    // Handle the Whatsapp Message Error or Success
    if ($err) {
        echo json_encode(['success' => false, 'code' => "2", 'message' => $err]);
        $file_content = "error on email sent : $err \n";
        file_put_contents($filename, $file_content, FILE_APPEND);
    } else {
        $file_content = "Mail Sent Successfully: Sender-$sender, To-$to, CC-$cc\n\n";
        file_put_contents($filename, $file_content, FILE_APPEND);
        echo json_encode(['success' => true, 'message' => "Email sent successfully."]);
    }
    
} else {
    echo json_encode(['success' => false, 'code' => "3", 'message' => "Error in form submission."]);
}
?>