-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmail.php
More file actions
49 lines (43 loc) · 1.59 KB
/
smail.php
File metadata and controls
49 lines (43 loc) · 1.59 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
<?php
include('hms/include/config.php'); // Database connection
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Sanitize inputs
$name = mysqli_real_escape_string($con, $_POST['name']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$phone = mysqli_real_escape_string($con, $_POST['phone']);
// Insert into DB
$query = "INSERT INTO contact_us (name, email, phone, created_at)
VALUES ('$name', '$email', '$phone', NOW())";
if (mysqli_query($con, $query)) {
// Email configuration
$to = "swaroopsasmile3505@gmail.com"; // 🔁 Replace with your actual receiving email
$subject = "New Contact Form Submission";
$message = "
<html>
<head><title>Contact Form Submission</title></head>
<body>
<h3>New Contact Form Submission</h3>
<p><strong>Name:</strong> $name</p>
<p><strong>Email:</strong> $email</p>
<p><strong>Phone:</strong> $phone</p>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <$email>" . "\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "Success";
} else {
echo "Saved to DB, but email failed.";
}
} else {
http_response_code(500);
echo "Database Error: " . mysqli_error($con);
}
} else {
http_response_code(405); // Method Not Allowed
echo "Invalid request.";
}
?>
<!-- send_email.php file -->