Forked from franz-josef-kaiser/wpmail_exceptions.php
Last active
November 2, 2017 05:35
-
-
Save mayeenulislam/7ccb6845a3f0b77549eafffc21d7dc21 to your computer and use it in GitHub Desktop.
WP Mail Error/Exception handling and SMTP settings. ALWAYS use the Kaiser's version - it's safer. This forked version is just to catch errors in the case of non-admin users.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* NOTICE_____________________________________________________________________ | |
* ALWAYS use the Kaiser's version - it's safer. | |
* This forked version is just to catch errors in the case of non-admin users. | |
* --------------------------------------------------------------------------- | |
*/ | |
defined( 'ABSPATH' ) OR exit; | |
/** | |
* Plugin Name: (WCM) PHPMailer Exceptions & SMTP | |
* Description: WordPress by default returns <code>FALSE</code> instead of an <code>Exception</code>. This plugin fixes that. | |
*/ | |
add_action( 'phpmailer_init', 'WCMphpmailerException' ); | |
function WCMphpmailerException( $phpmailer ) | |
{ | |
if ( ! defined( 'WP_DEBUG' ) OR ! WP_DEBUG ) | |
{ | |
$phpmailer->SMTPDebug = 0; | |
$phpmailer->debug = 0; | |
return; | |
} | |
// Dispaly error to everybody other than administrator. | |
// Enable SMTP | |
# $phpmailer->IsSMTP(); | |
$phpmailer->SMTPDebug = 2; | |
$phpmailer->debug = 1; | |
$data = apply_filters( | |
'wp_mail', | |
compact( 'to', 'subject', 'message', 'headers', 'attachments' ) | |
); | |
// Show what we got | |
print htmlspecialchars( var_export( $phpmailer, true ) ); | |
$error = null; | |
try | |
{ | |
$sent = $phpmailer->Send(); | |
! $sent AND $error = new WP_Error( 'phpmailer-error', $sent->ErrorInfo ); | |
} | |
catch ( phpmailerException $e ) | |
{ | |
$error = new WP_Error( 'phpmailer-exception', $e->errorMessage() ); | |
} | |
catch ( Exception $e ) | |
{ | |
$error = new WP_Error( 'phpmailer-exception-unknown', $e->getMessage() ); | |
} | |
if ( is_wp_error( $error ) ) | |
return printf( | |
"%s: %s", | |
$error->get_error_code(), | |
$error->get_error_message() | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined( 'ABSPATH' ) OR exit; | |
/** | |
* Plugin Name: (WCM) PHPMailer SMTP Settings | |
* Description: Enables SMTP servers, SSL/TSL authentication and SMTP settings. | |
*/ | |
add_action( 'phpmailer_init', 'phpmailerSMTP' ); | |
function phpmailerSMTP( $phpmailer ) | |
{ | |
# $phpmailer->IsSMTP(); | |
# $phpmailer->SMTPAuth = true; // Authentication | |
# $phpmailer->Host = ''; | |
# $phpmailer->Username = ''; | |
# $phpmailer->Password = ''; | |
# $phpmailer->SMTPSecure ='ssl'; // enable if required, 'tls' is another possible value | |
# $phpmailer->Host = ''; // SMTP Host | |
# $phpmailer->Port = 26; // SMTP Port | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment