What are some potential pitfalls to be aware of when implementing email forwarding with PHP?

One potential pitfall when implementing email forwarding with PHP is the risk of email headers being manipulated by malicious users, leading to spoofing or phishing attacks. To prevent this, it is important to properly sanitize and validate user input before using it in email headers.

// Sanitize and validate email address before using it in the headers
$forward_address = filter_var($_POST['forward_address'], FILTER_SANITIZE_EMAIL);

// Check if the email address is valid
if(filter_var($forward_address, FILTER_VALIDATE_EMAIL)) {
    // Proceed with forwarding the email
} else {
    // Handle invalid email address input
}