What are the potential risks of using the PHP mail() function without proper validation of email addresses?

Using the PHP mail() function without proper validation of email addresses can lead to potential risks such as sending emails to incorrect or malicious addresses, causing spam complaints, and damaging your sender reputation. To mitigate these risks, it is important to validate email addresses before using them in the mail() function to ensure that only legitimate and correctly formatted email addresses are used.

// Validate email address before using it in the mail() function
$email = "example@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Email address is valid, proceed with sending the email
    mail($email, "Subject", "Message");
} else {
    // Email address is invalid, handle the error accordingly
    echo "Invalid email address";
}