Are there any security considerations to keep in mind when setting up a custom email system in PHP?

When setting up a custom email system in PHP, it is important to consider security measures to prevent vulnerabilities such as email injection attacks. One way to mitigate this risk is by properly sanitizing user input before using it to construct email headers. This can be done by using the `filter_var()` function with the `FILTER_SANITIZE_EMAIL` filter to validate and sanitize email addresses.

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

// Construct email headers
$headers = "From: $email\r\n";

// Send email
mail('recipient@example.com', 'Subject', 'Message', $headers);