MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/.nvm/../public_html/brandessential/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/.nvm/../public_html/brandessential/send-enquiry.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

require './PHPMailer/src/Exception.php';
require './PHPMailer/src/PHPMailer.php';
require './PHPMailer/src/SMTP.php';

// Set header for JSON response
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Content-Type');

// Check if it's a POST request
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
    echo json_encode(["status" => "error", "message" => "Invalid request method"]);
    exit;
}

// Debug: Log POST data
error_log("POST data received: " . print_r($_POST, true));

// Collect and validate POST data
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$company = isset($_POST['company']) ? trim($_POST['company']) : '';
$subject = isset($_POST['subject']) ? trim($_POST['subject']) : '';
$phone = isset($_POST['phone']) ? trim($_POST['phone']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$message = isset($_POST['message']) ? trim($_POST['message']) : '';
$product = isset($_POST['product']) ? trim($_POST['product']) : '';

// Validate required fields
if (empty($name) || empty($subject) || empty($phone) || empty($email)) {
    echo json_encode(["status" => "error", "message" => "Please fill in all required fields"]);
    exit;
}

// Validate email format
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo json_encode(["status" => "error", "message" => "Please enter a valid email address"]);
    exit;
}

// Validate phone number (basic validation)
if (!preg_match('/^[0-9+\-\s()]{10,}$/', $phone)) {
    echo json_encode(["status" => "error", "message" => "Please enter a valid phone number"]);
    exit;
}

try {
    $mail = new PHPMailer(true);

    // Debug SMTP (disable in production)
    $mail->SMTPDebug = 0; // Set to 0 for production
    $mail->Debugoutput = function($str, $level) {
        error_log("PHPMailer debug: $str");
    };

    // Server settings
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'deepachandranr@gmail.com'; // Replace with your email
    $mail->Password = 'mlkm ebmb jrgl iykk'; // Replace with your app password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port = 465;
    
    // SSL/TLS Settings
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

    // Set timeout
    $mail->Timeout = 30;

    // Sender
    $mail->setFrom('deepachandranr@gmail.com', 'BRANDESSENTIAL'); // Replace with your email
    
    // Admin email
    $mail->addAddress('deepachandranr@gmail.com'); // Replace with your email
    $mail->isHTML(true);
    $mail->Subject = 'New Product Inquiry - ' . $product;
    
    // Admin email content
    $adminBody = "
    <html>
    <head>
        <style>
            body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
            .container { max-width: 600px; margin: 0 auto; padding: 20px; }
            .header { background: #232323; color: white; padding: 20px; text-align: center; border-radius: 10px 10px 0 0; }
            .content {  background: rgba(255, 255, 255, 0.10);backdrop-filter: blur(4px); padding: 30px; border-radius: 0 0 10px 10px; }
            .info-table { width: 100%; border-collapse: collapse; margin: 20px 0; }
            .info-table th, .info-table td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
            .info-table th { background-color: #0f47ff; color: white; font-weight: bold; }
            .product-highlight { background: #e8f2ff; padding: 15px; border-radius: 8px; margin: 15px 0; border-left: 4px solid #0f47ff; }
            .footer { text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd; color: #666; }
        </style>
    </head>
    <body>
        <div class='container'>
            <div class='header'>
                <h1>🛍️ New Product Inquiry</h1>
                <p>Someone is interested in your products!</p>
            </div>
            
            <div class='content'>
                <div class='product-highlight'>
                    <h3>📦 Product of Interest</h3>
                    <p><strong>$product</strong></p>
                </div>
                
                <h3>👤 Customer Details</h3>
                <table class='info-table'>
                    <tr><th>Name</th><td>$name</td></tr>
                    <tr><th>Email</th><td>$email</td></tr>
                    <tr><th>Phone</th><td>$phone</td></tr>
                    <tr><th>Company</th><td>" . ($company ? $company : 'Not specified') . "</td></tr>
                    <tr><th>Subject</th><td>$subject</td></tr>
                </table>
                
                " . ($message ? "<h3>💬 Message</h3><div style='background: white; padding: 15px; border-radius: 8px; border: 1px solid #ddd;'>$message</div>" : "") . "
                
                <div class='footer'>
                    <p>This inquiry was sent from your BRANDESSENTIAL website.</p>
                    <p>Please respond to the customer as soon as possible.</p>
                </div>
            </div>
        </div>
    </body>
    </html>";

    $mail->Body = $adminBody;

    // Send admin email
    if (!$mail->send()) {
        throw new Exception("Admin email failed: " . $mail->ErrorInfo);
    }

    // Reset for customer email
    $mail->clearAddresses();
    $mail->clearReplyTos();

    // Customer email
    $mail->addAddress($email, $name);
    $mail->Subject = 'Thank you for your inquiry - ' . $product;
    
    // Customer email content
    $customerBody = "
    <html>
    <head>
        <style>
            body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
            .container { max-width: 600px; margin: 0 auto; padding: 20px; }
            .header { background: #232323; color: white; padding: 30px; text-align: center; border-radius: 10px 10px 0 0; }
            .content {background: rgba(255, 255, 255, 0.10);backdrop-filter: blur(4px); padding: 30px; border-radius: 0 0 10px 10px; }
            .logo { font-size: 2em; font-weight: bold; margin-bottom: 10px; }
            .product-box { background: white; padding: 20px; border-radius: 10px; margin: 20px 0; border: 2px solid #0f47ff; }
            .contact-info { background: #e8f2ff; padding: 20px; border-radius: 10px; margin: 20px 0; }
            .footer { text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd; color: #666; }
            .highlight { color: #0f47ff; font-weight: bold; }
        </style>
    </head>
    <body>
        <div class='container'>
            <div class='header'>
                <div class='logo'>BRANDESSENTIAL</div>
                <h2>Thank You for Your Inquiry! 🎉</h2>
            </div>
            
            <div class='content'>
                <h3>Dear $name,</h3>
                
                <p>Thank you for your interest in our premium design products. We have received your inquiry and our team will get back to you within 24 hours.</p>
                
                <div class='product-box'>
                    <h3>📦 Product You're Interested In:</h3>
                    <p class='highlight'>$product</p>
                    <p><strong>Subject:</strong> $subject</p>
                </div>
                
                <h3>📋 Your Inquiry Details:</h3>
                <ul>
                    <li><strong>Name:</strong> $name</li>
                    <li><strong>Email:</strong> $email</li>
                    <li><strong>Phone:</strong> $phone</li>
                    " . ($company ? "<li><strong>Company:</strong> $company</li>" : "") . "
                </ul>
                
                " . ($message ? "<h3>💬 Your Message:</h3><div style='background: white; padding: 15px; border-radius: 8px; border: 1px solid #ddd; font-style: italic;'>\"$message\"</div>" : "") . "
                
                <div class='contact-info'>
                    <h3>📞 Contact Information</h3>
                    <p>If you have any urgent questions, feel free to reach out to us:</p>
                    <p>
                        <strong>Email:</strong> your-email@gmail.com<br>
                        <strong>Phone:</strong> +1 (555) 123-4567<br>
                        <strong>Website:</strong> www.brandessential.com
                    </p>
                </div>
                
                <div class='footer'>
                    <p>Best regards,<br>
                    <strong>BRANDESSENTIAL Team</strong></p>
                    <p><em>Creating Premium Design Solutions</em></p>
                </div>
            </div>
        </div>
    </body>
    </html>";

    $mail->Body = $customerBody;

    // Send customer email
    if (!$mail->send()) {
        throw new Exception("Customer email failed: " . $mail->ErrorInfo);
    }

    // Log successful inquiry
    error_log("Successful inquiry from: $name ($email) for product: $product");

    echo json_encode([
        "status" => "success",
        "message" => "Thank you! Your inquiry has been sent successfully. We'll get back to you soon!"
    ]);

} catch (Exception $e) {
    error_log("Mailer Error: " . $e->getMessage());
    echo json_encode([
        "status" => "error",
        "message" => "Sorry, there was an error sending your inquiry. Please try again later.",
        "debug" => $e->getMessage() // Remove this in production
    ]);
}
?>

MMCT - 2023