How can error reporting be utilized effectively when encountering problems with PHPMailer?

When encountering problems with PHPMailer, error reporting can be utilized effectively by enabling debugging mode to get detailed error messages. This can help identify the root cause of the issue and troubleshoot it accordingly.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Enable debugging mode
$mail = new PHPMailer(true);
$mail->SMTPDebug = SMTP::DEBUG_SERVER;

// Rest of the PHPMailer configuration and sending email code