How can PHP be integrated with a contact form for email forwarding purposes?
To integrate PHP with a contact form for email forwarding purposes, you can use the PHP `mail()` function to send the form data to a specified email address. You will need to set up your HTML contact form with appropriate input fields and then create a PHP script to process the form data and send it via email.
<?php
if(isset($_POST['submit'])){
$to = "recipient@example.com";
$subject = "Contact Form Submission";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = "Name: $name\n";
$body .= "Email: $email\n";
$body .= "Message: $message\n";
if(mail($to, $subject, $body)){
echo "Message sent successfully!";
} else{
echo "Error sending message.";
}
}
?>
Keywords
Related Questions
- What potential issues can arise when using $_SERVER['PHP_SELF'] to get the current script name?
- How can the output of a template parser function be further processed before being displayed?
- In the provided PHP code snippet, what are some best practices for handling database connections and queries to avoid errors like "No index used in query/prepared statement"?