🚀 Email-to-Blog Setup Guide

Quick setup guide to get your email-to-blog system running in 5 minutes!

✅ Prerequisites

1 Check PHP IMAP Extension

php -m | grep imap

If not installed:

Ubuntu/Debian:

sudo apt-get install php-imap sudo systemctl restart apache2

CentOS/RHEL:

sudo yum install php-imap sudo systemctl restart httpd

Windows (XAMPP):

  1. 1. Open php.ini
  2. 2. Find ;extension=imap
  3. 3. Remove the ; to uncomment
  4. 4. Restart Apache

2 Configure Email Account

Option A: Gmail (Recommended)

1. Enable IMAP

2. Create App Password

3. Update .env file

BLOG_EMAIL_ADDRESS=blogs@yourdomain.com BLOG_EMAIL_PASSWORD=your-16-char-app-password BLOG_EMAIL_MAILBOX={imap.gmail.com:993/imap/ssl}INBOX

Option B: Office 365

BLOG_EMAIL_ADDRESS=blogs@yourdomain.com BLOG_EMAIL_PASSWORD=your-password BLOG_EMAIL_MAILBOX={outlook.office365.com:993/imap/ssl}INBOX

Option C: Custom Domain / cPanel

BLOG_EMAIL_ADDRESS=blogs@yourdomain.com BLOG_EMAIL_PASSWORD=your-password BLOG_EMAIL_MAILBOX={mail.yourdomain.com:993/imap/ssl}INBOX

3 Create Required Directories

# Create upload directory for blog images mkdir -p uploads/blog-images chmod 755 uploads/blog-images # Create logs directory mkdir -p logs chmod 755 logs

4 Test the System

Run manually to test:

cd api php email-to-blog.php

Check the output for any errors. You should see:

Starting email-to-blog processor Connected to mailbox Connected to database Found 0 new email(s) Email-to-blog processor completed successfully

5 Setup Cron Job

Make the script executable:

chmod +x cron/email-to-blog-cron.sh

Edit crontab:

crontab -e

Add one of these lines:

Every 30 minutes (recommended):

*/30 * * * * /path/to/cron/email-to-blog-cron.sh

Every 15 minutes (more frequent):

*/15 * * * * /path/to/cron/email-to-blog-cron.sh

Every hour:

0 * * * * /path/to/cron/email-to-blog-cron.sh

Save and exit. Verify cron is set:

crontab -l

6 Enable Blogger Permissions

Make sure at least one user has blogger privileges:

-- Via MySQL UPDATE users SET is_blogger = 1 WHERE username = 'your-username'; -- Or make admin user the default blogger UPDATE users SET is_blogger = 1 WHERE is_admin = 1 LIMIT 1;

7 Send Test Email

To: blogs@yourdomain.com
Subject: Test Blog Post

Body:

STATUS: draft CATEGORY: Test # This is a Test This is my first automated blog post! Pretty cool, right?

Wait 30 minutes (or however long your cron interval is)

Then check:

🔍 Quick Troubleshooting

Error: "Cannot connect to mailbox"

Solution:

  1. 1. Verify IMAP is enabled in email settings
  2. 2. Check firewall allows outbound port 993
  3. 3. Verify credentials in .env
  4. 4. For Gmail, use App Password (not regular password)

Error: "PHP Fatal error: Call to undefined function imap_open"

Solution: IMAP extension not installed

# Ubuntu/Debian sudo apt-get install php-imap sudo systemctl restart apache2 # Verify php -m | grep imap

Images not uploading

Solution:

# Check directory exists and is writable mkdir -p uploads/blog-images chmod 755 uploads/blog-images chown www-data:www-data uploads/blog-images # Linux

📊 Monitoring

View Logs

# Last 50 lines tail -n 50 logs/email-to-blog.log # Follow live tail -f logs/email-to-blog.log # Search for errors grep ERROR logs/email-to-blog.log # Count successful posts grep "Created blog post" logs/email-to-blog.log | wc -l

Admin Interface

Access the monitoring dashboard:

https://morsetrainerpro.com/admin-email-to-blog.html

Features:

🎉 You're Done!

Your email-to-blog system is now operational!

Next Steps:

  1. 1. Send your first real blog post
  2. 2. Monitor logs to ensure it's working
  3. 3. Add email templates to your email client
  4. 4. Share the blog email with your team

Happy Blogging! 📝✨

← Back to Blog Admin