What are some common errors that may occur when sending emails in PHP, and how can these errors be identified and resolved?

One common error when sending emails in PHP is not setting the "From" header correctly, which can result in the email being marked as spam or not being delivered at all. To resolve this, 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\r\n";

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