How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php
How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php How to send mail with phpmailer in core php
//// attach file
download file github rename src folder to PHPMailer
https://github.com/PHPMailer/PHPMailer/tree/master
<?php
include('../connection.php');
$getSmtpDetails=mysqli_query($conn,"SELECT * FROM `mail_smtp`");
$fetchRow=mysqli_fetch_assoc($getSmtpDetails);
$hostName=$fetchRow['Host'];
$hostUsername=$fetchRow['Username'];
$hostPassword=$fetchRow['Password'];
$hostSMTPSecure=$fetchRow['SMTPSecure'];
$Sender=$fetchRow['Sender'];
$AdminEmail1=$fetchRow['admin_mail1'];
$AdminEmail2=$fetchRow['admin_mail2'];
$AdminEmail3=$fetchRow['admin_mail3'];
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
require 'PHPMailer/Exception.php';
if (isset($_POST['name'], $_POST['phone'], $_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$updated_at=date('Y-m-d');
$created_at=date('Y-m-d');
$page_url = getCurrentUrl();
$sql=mysqli_query($conn,"INSERT INTO enquiry_form(name,email,phone,page_url,updated_at,created_at)VALUES('$name','$email','$phone','$page_url','$updated_at','$created_at')");
// Create PHPMailer instance
$mail = new PHPMailer(true);
try {
// SMTP Configuration
$mail->isSMTP();
$mail->Host = $hostName; // Replace with your actual SMTP host
$mail->SMTPAuth = true;
$mail->Username = $hostUsername; // SMTP username
$mail->Password = $hostPassword; // SMTP password
$mail->SMTPSecure = $hostSMTPSecure; // 'tls' or 'ssl'
$mail->Port = 587; // 587 for TLS, 465 for SSL
// ============ 1. Send Email to Admin ============
$mail->setFrom($Sender, 'TGC India'); // Sender
$mail->addAddress($AdminEmail1); // Admin email
$mail->addAddress($AdminEmail2);
$mail->addAddress($AdminEmail3);
$mail->addReplyTo($email, $name); // User reply-to
$mail->isHTML(false); // Use plain text
$mail->Subject = 'New Inquiry From Data Science 2025 AD DSTI';
$mail->Body = "Name: $name\nPhone: $phone\nEmail: $email\n";
$mail->send(); // ✅ Send to Admin
// ============ 2. Send Confirmation to User ============
$mail->clearAddresses(); // Clear previous recipient(s)
$mail->addAddress($email); // Send to user
$mail->Subject = 'Query Submitted';
$mail->Body = "Dear $name,\n\nThank you for submitting your query. We will get back to you soon.\n\nBest regards,\nTGC India";
$mail->send(); // ✅ Send to User
// Redirect to thank-you page
header("Location: https://www.tgcindia.com/thanks/");
exit;
} catch (Exception $e) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
} else {
echo "Invalid form submission.";
}
?>
Comments
Post a Comment