What are some best practices for handling errors in PHP scripts that involve sending emails?

When handling errors in PHP scripts that involve sending emails, it is important to catch any exceptions that may occur during the email sending process. This ensures that errors are properly handled and do not disrupt the flow of the script. One best practice is to use try-catch blocks to catch exceptions and log any errors that occur.

try {
    // Code to send email
    // Example: mail($to, $subject, $message);
} catch (Exception $e) {
    // Log the error
    error_log('Error sending email: ' . $e->getMessage());
}