How can encoding affect the display of text and links in emails sent via PHP?

When sending emails via PHP, encoding issues can arise if the text or links contain special characters or symbols. To ensure proper display, it is important to set the correct encoding for the email content. This can be achieved by using the mb_encode_mimeheader() function for text and the mb_encode_numericentity() function for links to properly encode them before sending the email.

// Set encoding for email content
$subject = 'Subject with special characters';
$subject = mb_encode_mimeheader($subject, 'UTF-8');

// Encode links in email content
$link = 'https://example.com/page?param=value';
$link = mb_encode_numericentity($link, [0x80, 0xffff, 0, 0xffff], 'UTF-8');

// Send email with encoded content
mail('recipient@example.com', $subject, 'Email content with encoded link: '.$link);