What are the potential pitfalls of using a fake email address as the sender when using the mail() function in PHP?

Using a fake email address as the sender when using the mail() function in PHP can lead to the email being marked as spam or rejected by the recipient's email server. To avoid this issue, it's recommended to use a legitimate email address that is associated with the domain from which the email is being sent.

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

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