What security considerations should be kept in mind when sending emails using PHP to prevent potential vulnerabilities or abuse?

When sending emails using PHP, it is important to sanitize user input to prevent potential vulnerabilities such as injection attacks. Additionally, always validate email addresses to ensure they are properly formatted and belong to legitimate users. To prevent abuse, consider implementing email throttling to limit the number of emails sent within a certain time frame.

// Sanitize user input
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);

// Validate email address
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Send email
    mail($email, 'Subject', 'Message');
} else {
    echo 'Invalid email address';
}