Are there any potential pitfalls or limitations when using the PHP mail function for receipt confirmation?

One potential pitfall when using the PHP mail function for receipt confirmation is that the email may be marked as spam by the recipient's email provider. To mitigate this issue, you can set the proper headers in the email to increase deliverability.

$to = "recipient@example.com";
$subject = "Receipt Confirmation";
$message = "Thank you for your purchase!";
$headers = "From: yourname@example.com\r\n";
$headers .= "Reply-To: yourname@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail($to, $subject, $message, $headers);