Skip to content

Instantly share code, notes, and snippets.

@Log1x
Created March 11, 2022 16:03
Show Gist options
  • Select an option

  • Save Log1x/2b53a11602711d8161b2edf0f5efd880 to your computer and use it in GitHub Desktop.

Select an option

Save Log1x/2b53a11602711d8161b2edf0f5efd880 to your computer and use it in GitHub Desktop.

Revisions

  1. Log1x created this gist Mar 11, 2022.
    29 changes: 29 additions & 0 deletions phpmailer-smtp.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    <?php

    use function Env\env;

    /**
    * Plugin Name: PHPMailer SMTP
    * Plugin URI: https://roots.io/bedrock/
    * Description: Simple PHPMailer SMTP configuration for Bedrock.
    * Version: 1.0.0
    * Author: Roots
    * Author URI: https://roots.io/
    * License: MIT License
    */

    add_filter('phpmailer_init', function ($mail) {
    $mail->isSMTP();

    $mail->SMTPAuth = true;
    $mail->Host = env('WP_ENV') === 'development' ? 'localhost' : env('WP_SMTP_HOST');
    $mail->Port = env('WP_ENV') === 'development' ? 1025 : 587;
    $mail->Username = env('WP_SMTP_USERNAME');
    $mail->Password = env('WP_SMTP_PASSWORD');
    $mail->Timeout = 10;

    $mail->setFrom(
    env('WP_SMTP_FORCEFROM'),
    env('WP_SMTP_FORCEFROMNAME')
    );
    });