What is the RFC 2822 standard and why is it important in PHP email handling?

The RFC 2822 standard defines the format for email messages, including headers and body content. It is important in PHP email handling because it ensures that emails are structured correctly and can be properly interpreted by email clients. To adhere to the RFC 2822 standard, PHP developers should format their email messages according to its specifications.

// Example of sending an email using PHP adhering to the RFC 2822 standard
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email message.";
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";

mail($to, $subject, $message, $headers);