setFrom('joe@example.com', 'Joe User'); //Send via SMTP $this->isSMTP(); //Equivalent to setting `Host`, `Port` and `SMTPSecure` all at once $this->Host = 'tls://smtp.example.com:587'; //Set an HTML and plain-text body, import relative image references $this->msgHTML($body, './images/'); //Show debug output $this->SMTPDebug = SMTP::DEBUG_SERVER; //Inject a new debug output handler $this->Debugoutput = static function ($str, $level) { echo "Debug level $level; message: $str\n"; }; } //Extend the send function public function send() { $this->Subject = '[Yay for me!] ' . $this->Subject; $r = parent::send(); echo 'I sent a message with subject '. $this->Subject; return $r; } } //Now creating and sending a message becomes simpler when you use this class in your app code try { //Instantiate your new class, making use of the new `$body` parameter $mail = new myPHPMailer(true, 'This is the message body'); // Now you only need to set things that are different from the defaults you defined $mail->addAddress('jane@example.com', 'Jane User'); $mail->Subject = 'Here is the subject'; $mail->addAttachment(__FILE__, 'myPHPMailer.php'); $mail->send(); //no need to check for errors - the exception handler will do it } catch (Exception $e) { //Note that this is catching the PHPMailer Exception class, not the global \Exception type! echo 'Caught a '. get_class($e) .': '. $e->getMessage(); }