What are the potential security risks associated with specifying the sender address in PHP mail function?

Specifying the sender address in the PHP mail function can potentially lead to email spoofing, where an attacker impersonates a legitimate sender. To mitigate this risk, it is recommended to set the "From" header using a trusted email address and domain. This will help prevent the email from being flagged as spam and protect the reputation of the sender's domain.

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

$headers = "From: Trusted Sender <trusted@example.com>";

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