What is the recommended method for sending emails in PHP, especially when handling form submissions?
When sending emails in PHP, especially when handling form submissions, it is recommended to use the PHP built-in function `mail()`. This function allows you to send emails directly from your PHP script without the need for additional libraries or dependencies.
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "recipient@example.com";
$subject = "Form Submission";
$message = "This is a test email.";
$headers = "From: sender@example.com";
if(mail($to, $subject, $message, $headers)) {
echo "Email sent successfully.";
} else {
echo "Email sending failed.";
}
}
?>