-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontact.php
More file actions
50 lines (43 loc) · 1.73 KB
/
contact.php
File metadata and controls
50 lines (43 loc) · 1.73 KB
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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer-master/src/Exception.php';
require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Retrieve form data
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$message = htmlspecialchars($_POST['message']);
// Create a new PHPMailer instance
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'Rizkhanrk01@gmail.com';
$mail->Password = 'kzbgnttfcpxrnvci';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Recipients
$mail->setFrom('Rizkhanrk01@gmail.com', 'PlaySphere Contact Form');
$mail->addAddress('Rizkhanrk01@gmail.com');
// Content
$mail->isHTML(true);
$mail->Subject = 'New Contact Form Submission';
$mail->Body = "
<h3>New Contact Form Submission</h3>
<p><strong>Name:</strong> {$name}</p>
<p><strong>Email:</strong> {$email}</p>
<p><strong>Message:</strong><br>{$message}</p>
";
$mail->AltBody = "New Contact Form Submission\n\nName: {$name}\nEmail: {$email}\nMessage: {$message}";
// Send the email
$mail->send();
echo "<script>alert('Message sent successfully!'); window.location.href = 'index.php';</script>";
} catch (Exception $e) {
echo "<script>alert('Message could not be sent. Mailer Error: {$mail->ErrorInfo}'); window.location.href = 'index.php';</script>";
}
}
?>