Last active
May 11, 2021 18:00
-
-
Save jrobinsonc/ae0a04d128336a22909aab52c3974e98 to your computer and use it in GitHub Desktop.
WordPress: SMTP configuration
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 | |
/** | |
* Set body as HTML. | |
*/ | |
function set_html_content_type() | |
{ | |
return 'text/html'; | |
} | |
add_filter('wp_mail_content_type', 'set_html_content_type'); | |
wp_mail('[email protected]', 'Subject', 'Message'); | |
// Reset content-type to avoid conflicts -- https://core.trac.wordpress.org/ticket/23578 | |
remove_filter('wp_mail_content_type', 'set_html_content_type'); |
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 | |
define('SMTP_DSN', 'smtp://user:pass@host:25?auth=1'); | |
// Do not edit below this line. | |
add_action('phpmailer_init', function($phpmailer) { | |
if (! defined('SMTP_DSN')) | |
return; | |
$smtp_data = parse_url(SMTP_DSN); | |
parse_str($smtp_data['query'], $smtp_data_query); | |
$phpmailer->isSMTP(); | |
$phpmailer->Host = $smtp_data['host']; | |
$phpmailer->SMTPAuth = isset($smtp_data_query['auth'])? boolval($smtp_data_query['auth']) : false; | |
$phpmailer->Port = $smtp_data['port']; | |
$phpmailer->Username = $smtp_data['user']; | |
$phpmailer->Password = $smtp_data['pass']; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment