How can PHPmailer's ErrorInfo be queried to determine if there was an error?

To determine if there was an error when sending an email using PHPmailer, you can check the ErrorInfo property after calling the send() method. If there was an error, the ErrorInfo property will contain a message describing the error. You can then use this message to handle the error appropriately in your code.

use PHPMailer\PHPMailer\PHPMailer;

$mail = new PHPMailer();

// set up mail parameters

if(!$mail->send()) {
    echo "Message could not be sent. Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}