How can one ensure that the desired sender address is consistently displayed across email clients when sending emails using PHP?

When sending emails using PHP, the sender address may not always display consistently across email clients due to differences in how they interpret the email headers. To ensure the desired sender address is consistently displayed, you should set both the "From" and "Reply-To" headers in the email message. This way, the sender address will be displayed correctly in most email clients.

$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: Your Name <youremail@example.com>\r\n";
$headers .= "Reply-To: youremail@example.com\r\n";

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