How can email header injection be prevented in PHP form mailers?

Email header injection can be prevented in PHP form mailers by sanitizing user input to ensure that it does not contain any additional headers. This can be done by using functions like `filter_var()` or `htmlspecialchars()` to escape special characters. Additionally, setting the `Content-Type` header explicitly can help prevent injection attacks.

// Sanitize user input to prevent email header injection
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$message = htmlspecialchars($_POST['message']);

// Set the Content-Type header to prevent injection attacks
$headers = "Content-Type: text/plain; charset=UTF-8";

// Send the email using the sanitized input and headers
mail($email, "Subject", $message, $headers);