How can the PHP code be modified to prevent question marks from appearing in the email content when viewed on certain email providers?

The issue of question marks appearing in email content on certain email providers can be solved by setting the email content type to UTF-8 and encoding the email subject and body using the mb_encode_mimeheader function in PHP.

// Set the email content type to UTF-8
$headers = 'Content-type: text/html; charset=UTF-8';

// Encode the email subject and body using mb_encode_mimeheader
$subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
$body = mb_encode_mimeheader($body, 'UTF-8');

// Send the email with the updated headers
mail($to, $subject, $body, $headers);