Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Last active May 28, 2024 07:30

Revisions

  1. franz-josef-kaiser revised this gist Apr 22, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion wpmail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,6 @@ 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
  2. franz-josef-kaiser revised this gist Sep 11, 2015. 2 changed files with 14 additions and 12 deletions.
    10 changes: 6 additions & 4 deletions wpmail_exceptions.php
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,13 @@
    add_action( 'phpmailer_init', 'WCMphpmailerException' );
    function WCMphpmailerException( $phpmailer )
    {
    if ( ! defined( 'WP_DEBUG' ) OR ! WP_DEBUG )
    if ( ! defined( 'WP_DEBUG' ) OR ! WP_DEBUG )
    {
    $phpmailer->SMTPDebug = 0;
    $phpmailer->debug = 0;
    return;
    }

    if ( ! current_user_can( 'manage_options' ) )
    return;

    @@ -27,22 +28,23 @@ function WCMphpmailerException( $phpmailer )
    compact( 'to', 'subject', 'message', 'headers', 'attachments' )
    );

    // Show what we got
    current_user_can( 'manage_options' )
    AND print htmlspecialchars( var_export( $phpmailer, true ) );

    $error = null;
    try
    {
    $sent = $phpmailer->Send();
    ! $sent AND $error = new WP_Error( 'phpmailerError', $sent->ErrorInfo );
    ! $sent AND $error = new WP_Error( 'phpmailer-error', $sent->ErrorInfo );
    }
    catch ( phpmailerException $e )
    {
    $error = new WP_Error( 'phpmailerException', $e->errorMessage() );
    $error = new WP_Error( 'phpmailer-exception', $e->errorMessage() );
    }
    catch ( Exception $e )
    {
    $error = new WP_Error( 'defaultException', $e->getMessage() );
    $error = new WP_Error( 'phpmailer-exception-unknown', $e->getMessage() );
    }

    if ( is_wp_error( $error ) )
    16 changes: 8 additions & 8 deletions wpmail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,12 @@
    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
    # $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
    }
  3. franz-josef-kaiser revised this gist Jun 22, 2013. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion wpmail_exceptions.php
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    */

    add_action( 'phpmailer_init', 'WCMphpmailerException' );
    function WCMphpmailerException( &$phpmailer )
    function WCMphpmailerException( $phpmailer )
    {
    if ( ! defined( 'WP_DEBUG' ) OR ! WP_DEBUG )
    {
    2 changes: 1 addition & 1 deletion wpmail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    */

    add_action( 'phpmailer_init', 'phpmailerSMTP' );
    function phpmailerSMTP( &$phpmailer )
    function phpmailerSMTP( $phpmailer )
    {
    # $phpmailer->IsSMTP();
    # $phpmailer->SMTPAuth = true; // Authentication
  4. franz-josef-kaiser revised this gist Jun 22, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions wpmail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -9,11 +9,11 @@
    function phpmailerSMTP( &$phpmailer )
    {
    # $phpmailer->IsSMTP();
    # $phpmailer->SMTPAuth = true; // Authentication
    # $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
    # $phpmailer->Port = 26; // SMTP Port
    }
  5. franz-josef-kaiser created this gist Jun 22, 2013.
    54 changes: 54 additions & 0 deletions wpmail_exceptions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    <?php
    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;
    }
    if ( ! current_user_can( 'manage_options' ) )
    return;

    // Enable SMTP
    # $phpmailer->IsSMTP();
    $phpmailer->SMTPDebug = 2;
    $phpmailer->debug = 1;

    $data = apply_filters(
    'wp_mail',
    compact( 'to', 'subject', 'message', 'headers', 'attachments' )
    );

    current_user_can( 'manage_options' )
    AND print htmlspecialchars( var_export( $phpmailer, true ) );

    $error = null;
    try
    {
    $sent = $phpmailer->Send();
    ! $sent AND $error = new WP_Error( 'phpmailerError', $sent->ErrorInfo );
    }
    catch ( phpmailerException $e )
    {
    $error = new WP_Error( 'phpmailerException', $e->errorMessage() );
    }
    catch ( Exception $e )
    {
    $error = new WP_Error( 'defaultException', $e->getMessage() );
    }

    if ( is_wp_error( $error ) )
    return printf(
    "%s: %s",
    $error->get_error_code(),
    $error->get_error_message()
    );
    }
    19 changes: 19 additions & 0 deletions wpmail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?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
    }