Server IP : 103.49.131.241  /  Your IP : 216.73.216.234
Web Server : LiteSpeed
System : Linux cpindia.liteserverdns.in 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : flightsc ( 2923)
PHP Version : 8.2.29
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0750) :  /home/flightsc/giftingonline.in/../greentripo.flightscapez.com/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/flightsc/giftingonline.in/../greentripo.flightscapez.com/send-enquiry.php
<?php
header('Content-Type: application/json');

// =============== CONFIGURATION ===============
$adminEmail = ".com";  // Admin/support email
$fromEmail  = "info@greentripo.com";  // Verified sender
$companyName = "GreenTripo";
$supportPhone = "+1-805-702-1258";

// =============== INPUT SANITIZATION ===============
function sanitizeInput($data) {
    return htmlspecialchars(strip_tags(trim($data)), ENT_QUOTES, 'UTF-8');
}

// Collect form data
$formData = [
    'full_name' => sanitizeInput($_POST['full_name'] ?? ''),
    'email' => filter_var($_POST['email'] ?? '', FILTER_SANITIZE_EMAIL),
    'phone' => sanitizeInput($_POST['phone'] ?? ''),
    'country_code' => sanitizeInput($_POST['country_code'] ?? ''),
    'subject' => sanitizeInput($_POST['subject'] ?? 'Contact Enquiry'),
    'message' => sanitizeInput($_POST['message'] ?? ''),
    'referring_page' => sanitizeInput($_POST['referring_page'] ?? '') // Capture referring page URL
];

// =============== VALIDATION ===============
$errors = [];

if (empty($formData['full_name']) || !preg_match('/^[a-zA-Z\s]{3,}$/', $formData['full_name'])) {
    $errors['full_name'] = 'Full name is required and must be at least 3 characters long (letters and spaces only).';
}

if (empty($formData['email']) || !filter_var($formData['email'], FILTER_VALIDATE_EMAIL)) {
    $errors['email'] = 'Valid email is required.';
}

if (empty($formData['phone']) || !preg_match('/^[0-9]{10,15}$/', $formData['phone'])) {
    $errors['phone'] = 'Phone number must be 10 to 15 digits.';
}

if (empty($formData['subject'])) {
    $errors['subject'] = 'Subject is required.';
}

if (empty($formData['message'])) {
    $errors['message'] = 'Message cannot be empty.';
}

// Return validation errors
if (!empty($errors)) {
    http_response_code(400);
    echo json_encode([
        'status' => 'error',
        'message' => 'Validation failed',
        'errors' => $errors
    ]);
    exit;
}

// =============== EMAIL CONTENT ===============
$adminSubject = "New Contact Enquiry: " . $formData['subject'];
$adminBody = "You have received a new enquiry:\n\n";
$adminBody .= "Name: {$formData['full_name']}\n";
$adminBody .= "Email: {$formData['email']}\n";
$adminBody .= "Phone: +" . ($formData['country_code'] ?: '') . " {$formData['phone']}\n";
$adminBody .= "Subject: {$formData['subject']}\n";
$adminBody .= "Message:\n{$formData['message']}\n";
$adminBody .= "Referring Page: {$formData['referring_page']}\n"; // Added referring page
$adminBody .= "\nReceived at: " . date('Y-m-d H:i:s');

$customerSubject = "Thank you for contacting {$companyName}";
$customerBody = "Dear {$formData['full_name']},\n\n";
$customerBody .= "Thank you for reaching out to {$companyName}. We have received your message regarding \"{$formData['subject']}\".\n\n";
$customerBody .= "Your Message:\n{$formData['message']}\n\n";
$customerBody .= "Our support team will get back to you shortly.\n";
$customerBody .= "For urgent matters, call us at {$supportPhone}.\n\n";
$customerBody .= "Best regards,\n{$companyName} Team";

// =============== EMAIL HEADERS ===============
$headers = [
    'From' => $fromEmail,
    'Reply-To' => $formData['email'],
    'X-Mailer' => 'PHP/' . phpversion(),
    'Content-Type' => 'text/plain; charset=UTF-8'
];

// Format headers
$formattedHeaders = '';
foreach ($headers as $key => $value) {
    $formattedHeaders .= "$key: $value\r\n";
}

// =============== SEND EMAILS ===============
try {
    $adminSent = mail($adminEmail, $adminSubject, $adminBody, $formattedHeaders);

    // Use a different Reply-To for customer mail
    $customerHeaders = str_replace($formData['email'], $fromEmail, $formattedHeaders);
    $customerSent = mail($formData['email'], $customerSubject, $customerBody, $customerHeaders);

    if ($adminSent && $customerSent) {
        echo json_encode([
            'status' => 'success',
            'message' => 'Thank you! Your enquiry has been submitted successfully.'
        ]);
    } else {
        throw new Exception('Email sending failed.');
    }
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode([
        'status' => 'error',
        'message' => 'Something went wrong while sending your enquiry. Please try again later or contact us directly at ' . $supportPhone
    ]);
    error_log("Email Error: " . $e->getMessage());
}