Created
December 19, 2024 20:59
Use Mailgun as WordPress SMTP email sending
This file contains hidden or 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 | |
/** | |
* 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