Why is it important to avoid using the customer's email address as the "From" address in email headers when sending emails via PHP scripts?

It is important to avoid using the customer's email address as the "From" address in email headers when sending emails via PHP scripts because it can lead to spoofing and phishing attacks. Instead, it is recommended to use a generic email address that is controlled by the sender to ensure the authenticity of the email. This helps to protect both the sender and the recipient from potential security risks.

$from_email = "noreply@example.com";
$from_name = "Example Company";

$to_email = "customer@example.com";
$subject = "Your Order Confirmation";
$message = "Thank you for your order.";

$headers = "From: $from_name <$from_email>\r\n";
$headers .= "Reply-To: $from_email\r\n";

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