What are some common PHP scripts or resources for creating email forms?
Creating email forms in PHP requires handling form submission, validating input, and sending the email. One common approach is to use the PHP `mail()` function to send the email. This function takes parameters for the recipient email address, subject, message, and additional headers.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$recipient = "recipient@example.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: " . $_POST['email'];
if (mail($recipient, $subject, $message, $headers)) {
echo "Email sent successfully!";
} else {
echo "Email sending failed.";
}
}
?>
Keywords
Related Questions
- What best practices should PHP beginners follow when creating forms to prevent errors and ensure proper functionality?
- What are the drawbacks of not restructuring the database design when facing challenges with array filtering in PHP?
- How can PHP developers effectively troubleshoot and resolve errors related to database queries and JSON data manipulation?