What are common issues when displaying emails in PHP that are sent as plain text or HTML?

Common issues when displaying emails in PHP that are sent as plain text or HTML include improper rendering of special characters, incorrect line breaks, and potential security vulnerabilities if HTML content is not properly sanitized. To solve these issues, you can use PHP's built-in functions like htmlspecialchars() to escape special characters and nl2br() to properly handle line breaks when displaying plain text emails. Additionally, if displaying HTML emails, make sure to sanitize the content using functions like strip_tags() to prevent XSS attacks.

// Example code to display plain text email with proper line breaks and escaping special characters
$emailContent = "Hello, this is a plain text email with special characters like < and >.";
echo nl2br(htmlspecialchars($emailContent));

// Example code to display HTML email with sanitized content
$htmlContent = "<h1>Welcome</h1><p>This is an HTML email with <script>alert('XSS attack!');</script></p>";
echo strip_tags($htmlContent, '<h1><p>'); // Only allow <h1> and <p> tags, strip other tags and attributes