Server IP : 103.191.208.50 / Your IP : 216.73.216.226 Web Server : LiteSpeed System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64 User : celkcksm ( 1031) PHP Version : 5.6.40 Disable Function : show_source, system, shell_exec, passthru, exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/celkcksm/bmtrust.org.in/../rmpharma.in/backup-21-02-25/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'php_mailer/Exception.php'; require 'php_mailer/PHPMailer.php'; require 'php_mailer/SMTP.php'; $recipient_address = "gitanjali.cp@gmail.com"; // Recipient's email address if ($_SERVER['REQUEST_METHOD'] === 'POST') { $mail_type = isset($_POST['mail_type']) ? trim($_POST['mail_type']) : ''; if (empty($mail_type)) { echo json_encode(['status' => false, 'message' => 'Form type not provided.']); exit; } $mail = new PHPMailer(true); try { $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'waytoadmissions21@gmail.com'; $mail->Password = 'lgle pkre mzzy sebw'; $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; $mail->Port = 465; $mail->isHTML(true); $name = isset($_POST['name']) ? trim($_POST['name']) : ''; $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $phone = isset($_POST['phone']) ? trim($_POST['phone']) : ''; $course = isset($_POST['course']) ? trim($_POST['course']) : ''; $address = isset($_POST['address']) ? trim($_POST['address']) : ''; // Admission form uses 'address' as message field $dob = isset($_POST['dob']) ? trim($_POST['dob']) : ''; $gender = isset($_POST['gender']) ? trim($_POST['gender']) : ''; $qualification = isset($_POST['qualification']) ? trim($_POST['qualification']) : ''; // Validate common fields $errors = validateCommonFields($name, $email, $phone, $course, $address); // Using address instead of message for admission form if (!empty($errors)) { echo json_encode(['status' => false, 'message' => implode(", ", $errors)]); exit; } $mail_subject = ($mail_type === 'admission_form') ? 'Admission Form Submission - ' . date('d-m-Y') : 'Enquiry Form Submission - ' . date('d-m-Y'); $mail_body = createMailBody($name, $email, $phone, $course, $address, $dob, $gender, $qualification); $mail->setFrom($email, $name); $mail->addAddress($recipient_address); $mail->Subject = $mail_subject; $mail->Body = $mail_body; $mail->send(); echo json_encode(['status' => true, 'message' => 'Your message has been sent successfully!']); } catch (Exception $e) { echo json_encode(['status' => false, 'message' => 'Message could not be sent. Error: ' . $mail->ErrorInfo]); } } function validateCommonFields($name, $email, $phone, $course, $address) { $errors = []; if (empty($name)) { $errors[] = "Name is required."; } if (empty($email)) { $errors[] = "Email is required."; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = "Invalid email format."; } if (empty($phone)) { $errors[] = "Phone number is required."; } elseif (!preg_match("/^[0-9]{10,15}$/", $phone)) { $errors[] = "Phone number must be between 10 and 15 digits."; } if (empty($course)) { $errors[] = "Course is required."; } if (empty($address)) { $errors[] = "Address is required."; } elseif (strlen($address) < 10) { $errors[] = "Address must be at least 10 characters."; } return $errors; } function createMailBody($name, $email, $phone, $course, $address, $dob, $gender, $qualification) { $body = "Name: " . htmlspecialchars($name) . "<br>"; $body .= "Email: " . htmlspecialchars($email) . "<br>"; $body .= "Phone: " . htmlspecialchars($phone) . "<br>"; $body .= "Course: " . htmlspecialchars($course) . "<br>"; if (!empty($dob)) { $body .= "Date of Birth: " . htmlspecialchars($dob) . "<br>"; } if (!empty($gender)) { $body .= "Gender: " . htmlspecialchars($gender) . "<br>"; } if (!empty($qualification)) { $body .= "Qualification: " . htmlspecialchars($qualification) . "<br>"; } if (!empty($address)) { $body .= "Address: " . htmlspecialchars($address) . "<br>"; } return $body; } ?>