What are the potential pitfalls of not having a properly configured mail server on a dedicated root server when using PHP for email notifications?

Potential pitfalls of not having a properly configured mail server on a dedicated root server when using PHP for email notifications include emails not being sent or being marked as spam by recipients. To solve this issue, ensure that the mail server is properly configured with correct DNS settings, SPF records, and reverse DNS lookup.

// Example PHP code snippet to send an email using a properly configured mail server
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com";

// Send email
if (mail($to, $subject, $message, $headers)) {
    echo "Email sent successfully.";
} else {
    echo "Email sending failed.";
}