What are the key considerations and pitfalls to be aware of when attempting to handle email sending in PHP without external classes?

When attempting to handle email sending in PHP without external classes, key considerations include ensuring proper validation of user input, implementing necessary headers for the email, and handling potential errors effectively. Pitfalls to be aware of include security vulnerabilities due to improper input validation, emails being marked as spam due to missing headers, and failure to handle errors leading to undelivered emails.

$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email sent from PHP.";
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";

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