How to override PHPMAILER exceptions?

how to install phpmailer
phpmailer documentation
how to install phpmailer in xampp
phpmailer download
phpmailer example
phpmailer autoload
phpmailer reply to
phpmailer addaddress

i'm sending emails via phpmailer and i want to override the exceptions as when you send an email and that fail you can have the error message via :

echo json_encode"{$mail->ErrorInfo}";

but when the error is

"Empty body"

i would like to display something else. Any solution ? Thanks

$new_msg = json_encode"{$mail->ErrorInfo}";

if ($new_msg == 'Empty body') {
  throw new CustomException("You custom message ");
} 

Wherever you are calling this function, catch the expectation there and show it to the user.

try {
        if ($new_msg == 'Empty body') {
          throw new CustomException("You custom message ");
       } 
    } catch (CustomException $ex) {
        //This is where you can have your own handling, exceptions that you want to handle separately 
    } catch (Exception $ex) {
       // this part will handle general exceptions
        // and show user some general error message
    }

PHPMailer\PHPMailerPHPMailer, \PHPMailer\PHPMailerPHPMailer Whether to throw exceptions for errors. Override this function to load your own SMTP implementation, or set one with� I have a custom class which extends PHPMailer, and I want to override the send function. This appears to be working, but I'm having trouble wrapping my head around if parent::send() is working on the active object or just randomly sending whatever.

You can put your echo in a variable and then do an if check to display something else.

$new_msg = json_encode"{$mail->ErrorInfo}";

if ($new_msg == 'Empty body') {
 echo 'You put here whatever you want';
} else {
 echo json_encode"{$mail->ErrorInfo}";
}

How to Use PHPMailer: Examples, Debugging, SMTP Settings, Adding Exception class will help you handle errors and debug them. In PHP it works similarly to the other programming languages. So, without it,� When it comes to adding email functionality to your PHP app, PHPMailer class is the winning option. It is compatible with most of the PHP frameworks (Laravel or Symfony are based on the SwiftMailer library, though, but it is still possible to use PHPMailer as well.)

Just catch the Exception and do something completely different!

try {
   $something->thatWillThrowAnException();
} catch (Exception $e) {
    // Do anything you want here!
}

PHPMailer complete tutorial (2018): send emails with PHP, As a minimum, you want to include the main PHPMailer class, the Exception class (for Note that this function will override both Body and AltBody attributes. Find answers to PHPMailer: Cannot override final method Exception::__clone() from the expert community at Experts Exchange

PHPMailer/PHPMailer: The classic email sending library for , library for PHP. Contribute to PHPMailer/PHPMailer development by creating an account on GitHub. require 'path/to/PHPMailer/src/Exception.php'; require� The class’ constructor argument is set to TRUE to make PHPMailer use exceptions for error reporting. If you prefer not to use exceptions, just omit the argument (or set it to FALSE). In this case you need to check the send () method return value and look for the error message in the $ErrorInfo attribute:

#23291 (wp_mail should handle phpmailer exceptions instead of , wp_mail should handle phpmailer exceptions instead of ignoring them false or WP_Error so it still will be compatible with plugins which override wp_mail, and� Step 2: Install PHPMailer. Extract downloaded zip file and copy the PHPmailer folder. After that open thrid party folder of your codeigniter application and past the PHPMailer folder there. This folder include Exception.php, Oauth.php, PHPMailer.php, POP.php and SMTP.php files. Step 3: Create Phpmailer library file

PHPMailer just keeps loading and returns nothing error wise!, PHPMailer just keeps loading and returns nothing error wise! use PHPMailer\ PHPMailer\Exception; require HELPERS_PATH. Of course you can keep overriding variables in PHPMailer as well, but that's messy at best. \PHPMailer\PHPMailer\Exception Returns string — The assembled message body. Inherited from \PHPMailer\PHPMailer\PHPMailer Set or reset instance properties.