How can the mail() function in PHP be used to set the priority of an email?

To set the priority of an email sent using the mail() function in PHP, you can include additional headers in the mail function call. The "X-Priority" header can be set to a value between 1 (highest) and 5 (lowest) to indicate the priority of the email. This allows you to prioritize important emails over less urgent ones.

$to = 'recipient@example.com';
$subject = 'Test Email with Priority';
$message = 'This is a test email with priority set.';
$headers = 'X-Priority: 1' . "\r\n";
$headers .= 'From: sender@example.com' . "\r\n";

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