What potential issues or pitfalls should be considered when using the "mail()" function in PHP?
One potential issue when using the "mail()" function in PHP is that it can be susceptible to email injection attacks if user input is not properly sanitized. To prevent this, always validate and sanitize user input before using it in the "mail()" function. This can be done by using functions like filter_var() or htmlspecialchars() to escape special characters.
// Sanitize user input before using it in the mail() function
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$subject = htmlspecialchars($_POST['subject']);
$message = htmlspecialchars($_POST['message']);
// Send the email using the sanitized input
mail($email, $subject, $message);