How can one avoid crashing a WordPress blog when trying to modify email content in PHP?

When modifying email content in PHP for a WordPress blog, it's important to use proper error handling to avoid crashing the site. One way to do this is by wrapping the code in a try-catch block and using the wp_mail() function to send the email. This function will handle errors gracefully and prevent the site from crashing if there are any issues with sending the email.

try {
    // Modify email content here
    $to = 'recipient@example.com';
    $subject = 'Subject';
    $message = 'Message';

    wp_mail($to, $subject, $message);
} catch (Exception $e) {
    error_log('Error sending email: ' . $e->getMessage());
}