How can the PHP-Mailer class improve the process of sending HTML emails in PHP?

Sending HTML emails in PHP can be a cumbersome process due to the need to format the email content properly. The PHP-Mailer class simplifies this process by providing a convenient way to send HTML emails with attachments, inline images, and custom headers.

<?php
require 'PHPMailer/PHPMailer.php';

// Create a new PHPMailer instance
$mail = new PHPMailer();

// Set the email content type to HTML
$mail->isHTML(true);

// Set the email subject and body
$mail->Subject = 'Example HTML Email';
$mail->Body = '<h1>Hello, world!</h1>';

// Set the sender and recipient
$mail->setFrom('sender@example.com', 'Sender Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');

// Send the email
if($mail->send()) {
    echo 'Email sent successfully';
} else {
    echo 'Email sending failed';
}