What are common errors when sending emails with PHP?

One common error when sending emails with PHP is not setting the 'From' header correctly, which can result in emails being marked as spam or not being delivered at all. To solve this issue, make sure to set the 'From' header with a valid email address.

$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com";

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