-
Notifications
You must be signed in to change notification settings - Fork 0
/
email-process.php
70 lines (57 loc) · 2.09 KB
/
email-process.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
// Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Include the database configuration file
include('includes/config.php');
// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['eid'])) {
// Assuming you get the inquiry ID from the POST data
$inquiry_id = isset($_POST['eid']) ? $_POST['eid'] : 0;
// Assuming you get the inquiry ID from the POST data
$inquiry_id = isset($_POST['eid']) ? $_POST['eid'] : 0;
// Fetch the reply message from the form
$reply_message = isset($_POST['reply']) ? $_POST['reply'] : '';
// Fetch inquiry details from the database based on the inquiry ID
$sql = "SELECT email, subject FROM contact_us WHERE enq_id = :inquiry_id";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':inquiry_id', $inquiry_id, PDO::PARAM_INT);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
if ($data) {
// Extract details
$receiver_email = $data['email'];
$subject = $data['subject'];
// Your admin email address
$admin_email = ''; // Your admin email
// Create a PHPMailer instance
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = ''; // Your SMTP username
$mail->Password = ''; // Your SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
// Recipients
$mail->setFrom($admin_email, 'Guide_Me');
$mail->addAddress($receiver_email);
// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = "Thank you for contacting us. <br><br>{$reply_message}";
// Send the email
$mail->send();
echo "Email sent successfully!";
} catch (Exception $e) {
echo "Failed to send email. Error: {$mail->ErrorInfo}";
}
} else {
echo "Inquiry not found.";
}
}