What are best practices for handling email headers and content in PHP?

When handling email headers and content in PHP, it is important to properly sanitize and validate user input to prevent email header injection attacks. One way to achieve this is by using the `filter_var` function with the `FILTER_SANITIZE_EMAIL` filter to sanitize email addresses. Additionally, always use proper encoding functions like `mb_encode_mimeheader` to handle special characters in email headers.

// Sanitize email address
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);

// Encode email subject for proper handling of special characters
$subject = mb_encode_mimeheader($_POST['subject']);

// Send email using sanitized email address and encoded subject
mail($email, $subject, $_POST['message']);