How can PHP be used to customize the sender name in an email?

To customize the sender name in an email using PHP, you can use the "From" header in the mail() function. By setting the "From" header to include both the sender's email address and their desired name, you can customize the sender name that appears in the recipient's inbox.

$to = 'recipient@example.com';
$subject = 'Subject of the email';
$message = 'This is the body of the email';

$sender_name = 'Custom Sender Name';
$sender_email = 'sender@example.com';

$headers = 'From: ' . $sender_name . ' <' . $sender_email . '>';

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