What are some common pitfalls when using the mail() function with additional parameters, such as in the example provided?
When using the mail() function with additional parameters, such as in the example provided, a common pitfall is not properly formatting the additional headers. To solve this issue, make sure to format the additional headers correctly with "\r\n" at the end of each header. This ensures that the email headers are parsed correctly by the mail server.
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);