What are the potential risks of sending emails without properly handling safe mode in PHP?

Sending emails without properly handling safe mode in PHP can lead to security vulnerabilities such as injection attacks or unauthorized access to sensitive information. To mitigate these risks, it is important to sanitize user input and validate email addresses before sending them.

// Example of sanitizing user input and validating email address before sending email

$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);

if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Send email code here
} else {
    echo "Invalid email address";
}