Is using a Mailer class the best practice for handling special characters in email subjects in PHP?

When handling special characters in email subjects in PHP, using a Mailer class that properly encodes the subject is a good practice. This ensures that special characters are handled correctly and the subject appears correctly in the recipient's email client.

use PHPMailer\PHPMailer\PHPMailer;

// Create a new PHPMailer instance
$mail = new PHPMailer();

// Set the subject with special characters
$subject = 'Subject with special characters éàü';

// Encode the subject using PHPMailer's encodeHeader() method
$mail->Subject = $mail->encodeHeader($subject);

// Send the email
$mail->send();