-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.php
34 lines (29 loc) · 1.05 KB
/
submit.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
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Set the recipient email address
$to = '[email protected]';
// Set the email subject
$subject = 'New message from your website contact form';
// Compose the email message
$email_message = "Name: $name\n";
$email_message .= "Email: $email\n\n";
$email_message .= "Message:\n$message\n";
// Set additional headers
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
// Send the email
if (mail($to, $subject, $email_message, $headers)) {
// Email sent successfully
echo "<h2>Thank you for contacting us, $name!</h2>";
echo "<p>We will get back to you at $email as soon as possible.</p>";
echo "<p>Your message: $message</p>";
} else {
// Error sending email
echo "<h2>Sorry, there was a problem sending your message.</h2>";
}
} else {
// If someone tries to access this script directly without submitting the form
// you can redirect them back to the