Skip to content

Instantly share code, notes, and snippets.

@jeffward3283
Last active August 29, 2015 14:13
Show Gist options
  • Save jeffward3283/515a3e8282a83ac3e210 to your computer and use it in GitHub Desktop.
Save jeffward3283/515a3e8282a83ac3e210 to your computer and use it in GitHub Desktop.
<?php
//////////////////////////
# Set Emails as HTML
//////////////////////////
if(!function_exists('set_html_content_type')){
function set_html_content_type() {
return 'text/html';
}
}
/////////////////////////
# Send Email
/////////////////////////
// add_action('init', 'send_email_example');
function send_email_example(){
/////////////////////////
# Create the message
/////////////////////////
ob_start();
?>
<h1>HTML Email</h1>
<p>This email consists of an html message.</p>
<?php
$message = ob_get_contents();
ob_end_clean();
//////////////////////////
# Setup the parameters
//////////////////////////
$args = array(
'headers' => array(
'From: YourName <first@email.com>',
'Return-Path: me@myblog.com',
'MIME-Version: 1.0',
'Content-Type: text/html; charset=UTF-8',
'Cc: ReceiverName <second@email.com>',
'Bcc: Receiver2Name <third@email.com>',
),
'to' => array(
'ReceiverName <recipient1@example.com>',
'ReceiverName2 <recipient2@foo.example.com>',
),
'subject' => __('Lets Do This!', TEXTDOMAIN),
'message' => $message,
'attachments' => array(
WP_CONTENT_DIR.'/uploads/file_to_attach.doc',
),
);
//////////////////////////////////
# Apply Filters & Send Email
//////////////////////////////////
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
wp_mail ( $args['to'], $args['subject'], $args['message'], $args['headers'], $args['attachments'] );
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment