How can the E.V.A. principle be applied to improve the structure of PHP code for sending emails?

Issue: The structure of PHP code for sending emails can often become messy and hard to maintain over time. Applying the E.V.A. principle (Eliminate, Visualize, Automate) can help improve the structure by removing unnecessary code, visualizing the flow of the email sending process, and automating repetitive tasks.

// E.V.A. principle applied to improve the structure of PHP code for sending emails

// Eliminate unnecessary code
// Visualize the flow of the email sending process
// Automate repetitive tasks

// Function to send email
function sendEmail($to, $subject, $message) {
    // Code to set up email headers
    $headers = 'From: webmaster@example.com' . "\r\n";
    
    // Code to send email
    if (mail($to, $subject, $message, $headers)) {
        echo 'Email sent successfully';
    } else {
        echo 'Email sending failed';
    }
}

// Example usage of sendEmail function
sendEmail('recipient@example.com', 'Test Email', 'This is a test email message');