What are best practices for defining the character encoding in PHP email headers?

When sending emails with PHP, it is important to define the character encoding in the email headers to ensure that special characters are displayed correctly. To do this, you can use the "Content-Type" header with the charset parameter set to the appropriate encoding (e.g. UTF-8). This will ensure that the email content is properly encoded and displayed in the recipient's email client.

// Define the character encoding in email headers
$to = "recipient@example.com";
$subject = "Subject of the email";
$message = "Email content with special characters";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";

// Additional headers
$headers .= "From: sender@example.com" . "\r\n";

// Send the email
mail($to, $subject, $message, $headers);