What are some best practices for decoding email text in PHP to avoid errors or data corruption?

When decoding email text in PHP, it's important to use the correct encoding and functions to avoid errors or data corruption. One common issue is decoding emails that are encoded using base64 or quoted-printable encoding. To decode such emails correctly, you can use PHP's built-in functions like base64_decode() and quoted_printable_decode().

// Sample code to decode email text in PHP

// Assuming $emailText contains the encoded email text
$decodedText = quoted_printable_decode(base64_decode($emailText));

// Now $decodedText contains the decoded email text that can be used safely