Skip to content

Instantly share code, notes, and snippets.

@butlerblog
Last active August 20, 2025 11:39
Show Gist options
  • Select an option

  • Save butlerblog/c5c5eae5ace5bdaefb5d to your computer and use it in GitHub Desktop.

Select an option

Save butlerblog/c5c5eae5ace5bdaefb5d to your computer and use it in GitHub Desktop.

Revisions

  1. butlerblog revised this gist Jul 19, 2021. No changes.
  2. butlerblog revised this gist Sep 28, 2020. 2 changed files with 9 additions and 6 deletions.
    10 changes: 7 additions & 3 deletions wp_config.php
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,13 @@
    <?php

    /*
    * Set the following constants in wp-config.php
    * These should be added somewhere BEFORE the
    * constant ABSPATH is defined.
    * Set the following constants in wp-config.php.
    * These should be added somewhere BEFORE the constant ABSPATH is defined.
    *
    * Author: Chad Butler
    * Author URI: https://butlerblog.com
    *
    * For more information and instructions, see: https://b.utler.co/Y3
    */

    define( 'SMTP_USER', '[email protected]' ); // Username to use for SMTP authentication
    5 changes: 2 additions & 3 deletions wp_mail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,9 @@
    * define the using the wp_config.php example in this gist.
    *
    * Author: Chad Butler
    * Author URI: http://butlerblog.com
    * Author URI: https://butlerblog.com
    *
    * For more information and instructions, see:
    * http://b.utler.co/Y3
    * For more information and instructions, see: https://b.utler.co/Y3
    */
    add_action( 'phpmailer_init', 'send_smtp_email' );
    function send_smtp_email( $phpmailer ) {
  3. butlerblog revised this gist Nov 10, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion wp_mail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,11 @@
    */
    add_action( 'phpmailer_init', 'send_smtp_email' );
    function send_smtp_email( $phpmailer ) {
    $phpmailer->isSMTP();
    if ( ! is_object( $phpmailer ) ) {
    $phpmailer = (object) $phpmailer;
    }

    $phpmailer->Mailer = 'smtp';
    $phpmailer->Host = SMTP_HOST;
    $phpmailer->SMTPAuth = SMTP_AUTH;
    $phpmailer->Port = SMTP_PORT;
  4. butlerblog revised this gist Aug 8, 2017. 2 changed files with 28 additions and 23 deletions.
    17 changes: 17 additions & 0 deletions wp_config.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?php

    /*
    * Set the following constants in wp-config.php
    * These should be added somewhere BEFORE the
    * constant ABSPATH is defined.
    */

    define( 'SMTP_USER', '[email protected]' ); // Username to use for SMTP authentication
    define( 'SMTP_PASS', 'smtp password' ); // Password to use for SMTP authentication
    define( 'SMTP_HOST', 'smtp.example.com' ); // The hostname of the mail server
    define( 'SMTP_FROM', '[email protected]' ); // SMTP From email address
    define( 'SMTP_NAME', 'e.g Website Name' ); // SMTP From name
    define( 'SMTP_PORT', '25' ); // SMTP port number - likely to be 25, 465 or 587
    define( 'SMTP_SECURE', 'tls' ); // Encryption system to use - ssl or tls
    define( 'SMTP_AUTH', true ); // Use SMTP authentication (true|false)
    define( 'SMTP_DEBUG', 0 ); // for debugging purposes only set to 1 or 2
    34 changes: 11 additions & 23 deletions wp_mail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,9 @@
    * SMTP server. This improves reliability of wp_mail, and
    * avoids many potential problems.
    *
    * Values are constants set in wp-config.php. Be sure to
    * define the using the wp_config.php example in this gist.
    *
    * Author: Chad Butler
    * Author URI: http://butlerblog.com
    *
    @@ -11,28 +14,13 @@
    */
    add_action( 'phpmailer_init', 'send_smtp_email' );
    function send_smtp_email( $phpmailer ) {

    // Define that we are sending with SMTP
    $phpmailer->isSMTP();

    // The hostname of the mail server
    $phpmailer->Host = "smtp.example.com";

    // Use SMTP authentication (true|false)
    $phpmailer->SMTPAuth = true;

    // SMTP port number - likely to be 25, 465 or 587
    $phpmailer->Port = "587";

    // Username to use for SMTP authentication
    $phpmailer->Username = "yourusername";

    // Password to use for SMTP authentication
    $phpmailer->Password = "yourpassword";

    // Encryption system to use - ssl or tls
    $phpmailer->SMTPSecure = "tls";

    $phpmailer->From = "[email protected]";
    $phpmailer->FromName = "Your Name";
    $phpmailer->Host = SMTP_HOST;
    $phpmailer->SMTPAuth = SMTP_AUTH;
    $phpmailer->Port = SMTP_PORT;
    $phpmailer->Username = SMTP_USER;
    $phpmailer->Password = SMTP_PASS;
    $phpmailer->SMTPSecure = SMTP_SECURE;
    $phpmailer->From = SMTP_FROM;
    $phpmailer->FromName = SMTP_NAME;
    }
  5. butlerblog revised this gist Apr 5, 2015. 1 changed file with 23 additions and 23 deletions.
    46 changes: 23 additions & 23 deletions wp_mail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -12,27 +12,27 @@
    add_action( 'phpmailer_init', 'send_smtp_email' );
    function send_smtp_email( $phpmailer ) {

    // Define that we are sending with SMTP
    $phpmailer->isSMTP();
    // The hostname of the mail server
    $phpmailer->Host = "smtp.example.com";
    // Use SMTP authentication (true|false)
    $phpmailer->SMTPAuth = true;
    // SMTP port number - likely to be 25, 465 or 587
    $phpmailer->Port = "587";
    // Username to use for SMTP authentication
    $phpmailer->Username = "yourusername";
    // Password to use for SMTP authentication
    $phpmailer->Password = "yourpassword";
    // Encryption system to use - ssl or tls
    $phpmailer->SMTPSecure = "tls";
    $phpmailer->From = "your-email-address";
    $phpmailer->FromName = "Your Name";
    // Define that we are sending with SMTP
    $phpmailer->isSMTP();

    // The hostname of the mail server
    $phpmailer->Host = "smtp.example.com";

    // Use SMTP authentication (true|false)
    $phpmailer->SMTPAuth = true;

    // SMTP port number - likely to be 25, 465 or 587
    $phpmailer->Port = "587";

    // Username to use for SMTP authentication
    $phpmailer->Username = "yourusername";

    // Password to use for SMTP authentication
    $phpmailer->Password = "yourpassword";

    // Encryption system to use - ssl or tls
    $phpmailer->SMTPSecure = "tls";

    $phpmailer->From = "[email protected]";
    $phpmailer->FromName = "Your Name";
    }
  6. butlerblog created this gist Apr 5, 2015.
    38 changes: 38 additions & 0 deletions wp_mail_smtp.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    /**
    * This function will connect wp_mail to your authenticated
    * SMTP server. This improves reliability of wp_mail, and
    * avoids many potential problems.
    *
    * Author: Chad Butler
    * Author URI: http://butlerblog.com
    *
    * For more information and instructions, see:
    * http://b.utler.co/Y3
    */
    add_action( 'phpmailer_init', 'send_smtp_email' );
    function send_smtp_email( $phpmailer ) {

    // Define that we are sending with SMTP
    $phpmailer->isSMTP();

    // The hostname of the mail server
    $phpmailer->Host = "smtp.example.com";

    // Use SMTP authentication (true|false)
    $phpmailer->SMTPAuth = true;

    // SMTP port number - likely to be 25, 465 or 587
    $phpmailer->Port = "587";

    // Username to use for SMTP authentication
    $phpmailer->Username = "yourusername";

    // Password to use for SMTP authentication
    $phpmailer->Password = "yourpassword";

    // Encryption system to use - ssl or tls
    $phpmailer->SMTPSecure = "tls";

    $phpmailer->From = "your-email-address";
    $phpmailer->FromName = "Your Name";
    }