What are common pitfalls when trying to customize a form mailer in PHP?

One common pitfall when customizing a form mailer in PHP is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To solve this, always use functions like htmlspecialchars() or mysqli_real_escape_string() to sanitize user input before using it in your mailer script.

// Sanitize user input before using it in the mailer script
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$message = htmlspecialchars($_POST['message']);

// Example of sending an email using the sanitized user input
$to = "recipient@example.com";
$subject = "New message from $name";
$body = "Name: $name\nEmail: $email\nMessage: $message";

// Send the email
mail($to, $subject, $body);