[EDIT] FILE: submit.php
<?php session_start(); error_reporting(E_ALL); ini_set('display_errors', 1); use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'vendor/autoload.php'; // === One enquiry per IP per 4 hours === $ip = $_SERVER['REMOTE_ADDR']; $log_file = __DIR__ . '/ip_log.txt'; $ip_records = file_exists($log_file) ? file($log_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : []; $current_time = time(); $cleaned_records = []; $allowed = true; foreach ($ip_records as $record) { list($logged_ip, $timestamp) = explode('|', $record); // Keep only records within last 4 hours (1800 seconds) if ($current_time - (int)$timestamp < 1800) { $cleaned_records[] = $record; if ($logged_ip === $ip) { $allowed = false; } } } if (!$allowed) { echo "<script>alert('You can only submit once every half and hours. Please be patient.'); window.location.href = 'contact.php';</script>"; exit(); } // === Proceed only if allowed and POST === if ($_SERVER["REQUEST_METHOD"] == "POST") { // Sanitize and retrieve form fields $name = trim(strip_tags($_POST['name'] ?? '')); $email = trim(strip_tags($_POST['email'] ?? '')); $mobile = trim(strip_tags($_POST['phone'] ?? '')); $subject = trim(strip_tags($_POST['subject'] ?? '')); $message_text = trim(strip_tags($_POST['message'] ?? '')); // === Email via PHPMailer === $mail = new PHPMailer(true); try { $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'equiry.adjointinfocom@gmail.com'; $mail->Password = 'xueo xljn udct uasw'; // Use Gmail App Password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587; $mail->setFrom('equiry.adjointinfocom@gmail.com', 'Website Enquiry'); $mail->addAddress('info@adjointinfocom.com'); // $mail->addAddress('designer.adjoint@gmail.com'); $mail->isHTML(true); $mail->Subject = 'You have received an enquiry!'; $mail->Body = ' <html> <head> <style> /* Reset some defaults */ body, table, td, a { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } table, td { mso-table-lspace: 0pt; mso-table-rspace: 0pt; } img { -ms-interpolation-mode: bicubic; } body { margin: 0; padding: 0; font-family: Arial, sans-serif; background-color: #f4f4f4; } .email-container { max-width: 600px; margin: 20px auto; background: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 0 10px rgba(0,0,0,0.1); } .header { background: #007BFF; color: #ffffff; padding: 20px; text-align: center; } .header h1 { margin: 0; font-size: 24px; } .content { padding: 20px; color: #333333; line-height: 1.5; } .content table { width: 100%; border-collapse: collapse; margin-top: 10px; } .content td { padding: 8px; border: 1px solid #dddddd; } .content td:first-child { font-weight: bold; background-color: #f9f9f9; width: 30%; } .footer { text-align: center; padding: 15px; font-size: 12px; color: #777777; background: #f4f4f4; } @media screen and (max-width: 600px) { .email-container { width: 100% !important; } .content td { display: block; width: 100% !important; } .content td:first-child { background-color: transparent; font-weight: bold; } } </style> </head> <body> <div class="email-container"> <div class="header"> <h1>New Enquiry Received</h1> </div> <div class="content"> <p>You have received a new enquiry from your website:</p> <table> <tr><td>Name</td><td>' . htmlspecialchars($name) . '</td></tr> <tr><td>Email</td><td>' . htmlspecialchars($email) . '</td></tr> <tr><td>Phone</td><td>' . htmlspecialchars($mobile) . '</td></tr> <tr><td>Subject</td><td>' . htmlspecialchars($subject) . '</td></tr> <tr><td>Message</td><td>' . nl2br(htmlspecialchars($message_text)) . '</td></tr> </table> </div> <div class="footer"> © ' . date("Y") . ' Adjoint Infocom PVT LTD. All rights reserved. </div> </div> </body> </html>'; $mail->send(); // Log this IP to prevent next submission within 1 hour $cleaned_records[] = $ip . '|' . $current_time; file_put_contents($log_file, implode(PHP_EOL, $cleaned_records) . PHP_EOL, LOCK_EX); echo '<script>window.location.href = "thank-you.php";</script>'; exit(); } catch (Exception $e) { $_SESSION['message'] = "Mailer Error: " . $mail->ErrorInfo; header("Location: index.php"); exit(); } }
SAVE
CANCEL