What are the benefits and drawbacks of using a Mailer class instead of the mail() function in PHP?

Using a Mailer class instead of the mail() function in PHP offers benefits such as better encapsulation, easier maintenance, and the ability to easily switch between different mailing libraries. However, it may introduce additional complexity and require more initial setup compared to using the built-in mail() function.

// Example of using a Mailer class to send an email
class Mailer {
    public function sendEmail($to, $subject, $message) {
        // Code to send email using a mailing library
    }
}

$mailer = new Mailer();
$mailer->sendEmail('recipient@example.com', 'Subject', 'Message body');