How can the mail() function be enabled or configured on a Linux server for PHP scripts?

To enable the mail() function on a Linux server for PHP scripts, you need to ensure that a mail transfer agent (MTA) like Postfix or Sendmail is installed and properly configured on the server. Additionally, you may need to configure PHP settings related to email functionality in the php.ini file. Finally, you can test the mail() function by sending a simple email from a PHP script.

// Example PHP script to send an email using the mail() function
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email sent using the mail() function in PHP.";
$headers = "From: sender@example.com";

// Send email
if (mail($to, $subject, $message, $headers)) {
    echo "Email sent successfully.";
} else {
    echo "Email sending failed.";
}