Skip to content

Instantly share code, notes, and snippets.

@bahiirwa
Forked from danielpataki/action.php
Created November 27, 2016 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahiirwa/bc412582efa708528f9c563031fff031 to your computer and use it in GitHub Desktop.
Save bahiirwa/bc412582efa708528f9c563031fff031 to your computer and use it in GitHub Desktop.
WordPress Emails
function set_mail_html_content_type() {
return 'text/html';
}
add_action( 'publish_post', 'author_publish_notice', 10 ,2 );
function author_publish_notice( $ID, $post ) {
if( 'post' == $post->post_type ) {
return;
}
$to = 'author@email.com';
$subject = 'Your Article Is Online';
$message = '<h1>Congratulations!</h1> <p>Your article is now online and
is sure to receives trillions of comments. Please do hang around and answer any questions
viewers may have!</p> <p><a href="' . get_permalink( $ID ) . '">' . $post->post_title . '</a></p>';
add_filter( 'wp_mail_content_type', 'set_mail_html_content_type' );
wp_mail( $to, $subject, $message );
remove_filter( 'wp_mail_content_type', 'set_mail_html_content_type' );
}
<?php
$to = 'my@email.com';
$subject = 'Welcome To The Tutorial';
$message = 'Hello! I hope you are enjoying this article, it is great to see you!';
wp_mail( $to, $subject, $message );
?>
function set_mail_html_content_type() {
return 'text/html';
}
$to = 'my@email.com';
$subject = 'Welcome To The Tutorial';
$message = '<h1>Hello!</h1> <p>I hope you are enjoying this article, it is great to see you!</p>';
add_filter( 'wp_mail_content_type', 'set_mail_html_content_type' );
wp_mail( $to, $subject, $message );
remove_filter( 'wp_mail_content_type', 'set_mail_html_content_type' );
<?php wp_mail( $to, $subject, $message, $headers, $attachments ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment