X

How to Post to Your Blog Using Email

Snippets by IsItWP

Are you looking for a way to check every 15 minutes for new emails within the account you specify and post them? While there’s probably a plugin for this, we have created a quick code snippet that you can use to post to your blog using email in WordPress.

The subject of your email will be the title and text placed within the body of your email for the post content.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

add_action('shutdown', 'retrieve_post_via_mail');
function retrieve_post_via_mail() {
	flush(); 
	if(get_transient('retrieve_post_via_mail')) { 
		return;
	} else { 
		$mail = wp_remote_get(get_bloginfo('wpurl').'/wp-mail.php');
		if(!is_wp_error($mail)) { 
			set_transient('retrieve_post_via_mail', 1, 60 * 15); 
		} else {
			set_transient('retrieve_post_via_mail', 1, 60 * 5); 
		}
	}
}

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 19 best WordPress plugins for photographers and how to create a job application form in WordPress.

Comments  Leave a Reply

  1. oh. so stupid of me. it would be email address in ‘Post via e-mail’ in writing section isn’t sir? so sorry to bother you. have a nice day 🙂

    1. Yes it is the email in the settings post via email. If you have any questions please feel free to ask.

  2. excuse me sir. is it email from contact info (profile) or in general setting that this snippet would check? sorry about my english and this probably silly question. 🙂

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[60% OFF Today!]
[60% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]