What potential pitfalls should be considered when using mailto in PHP for email communication?

When using mailto in PHP for email communication, one potential pitfall to consider is the risk of email injection attacks. To prevent this, it is important to sanitize and validate user input before using it in the email headers. This can help to prevent malicious users from injecting additional headers or content into the email.

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

// Validate email address
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Send email using sanitized email address
    $to = $email;
    $subject = "Subject";
    $message = "Message";
    $headers = "From: yourname@example.com";

    mail($to, $subject, $message, $headers);
} else {
    echo "Invalid email address";
}