jun 14
This commit is contained in:
34
php/send_email.php
Normal file
34
php/send_email.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
// Collect form data
|
||||
$name = htmlspecialchars($_POST['name']);
|
||||
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
|
||||
$message = htmlspecialchars($_POST['message']);
|
||||
|
||||
// Validate email
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
echo "Invalid email format";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Email details
|
||||
$to = "veatio8@gmail.com";
|
||||
$subject = "New Contact Form Submission";
|
||||
$headers = "From: " . $email . "\r\n" .
|
||||
"Reply-To: " . $email . "\r\n" .
|
||||
"X-Mailer: PHP/" . phpversion();
|
||||
|
||||
$body = "Name: $name\n";
|
||||
$body .= "Email: $email\n\n";
|
||||
$body .= "Message:\n$message";
|
||||
|
||||
// Error handling with detailed information
|
||||
if (mail($to, $subject, $body, $headers)) {
|
||||
echo "Email sent successfully!";
|
||||
} else {
|
||||
// Use error_get_last() to capture the last error
|
||||
$error = error_get_last()['message'];
|
||||
echo "Failed to send email. Error: " . $error;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user