How can PHP developers ensure that the sender's email address is correctly displayed in the email header when using the mail() function?

When using the mail() function in PHP to send emails, developers can ensure that the sender's email address is correctly displayed in the email header by setting the "From" header in the additional headers parameter. This will specify the sender's email address that will be displayed in the recipient's email client.

$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com";

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