Skip to content

Instantly share code, notes, and snippets.

@ara303
Created December 19, 2024 20:59
Use Mailgun as WordPress SMTP email sending
<?php
/**
* Use Mailgun as WordPress's default SMTP sender instead of built-in mailer.
* All of these should be set for the best chance of email delivery.
* Create constant MAILGUN_PASSWORD in wp-config.php for secure storage of API secret.
*/
function use_mailgun_as_smtp( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.eu.mailgun.org'; // Or not if you're using NA
$phpmailer->Port = 587;
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Username = '[email protected]';
$phpmailer->Password = MAILGUN_PASSWORD;
$phpmailer->From = '[email protected]';
$phpmailer->FromName = 'Your Domain';
}
add_action( 'phpmailer_init', 'use_mailgun_as_smtp' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment