Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active May 11, 2021 18:00
Show Gist options
  • Save jrobinsonc/ae0a04d128336a22909aab52c3974e98 to your computer and use it in GitHub Desktop.
Save jrobinsonc/ae0a04d128336a22909aab52c3974e98 to your computer and use it in GitHub Desktop.
WordPress: SMTP configuration
<?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');
<?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