WordPress: SMTP configuration
<?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'];
});
<?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('test@server.com', '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');