Configuring Laravel SMTP Email and Queue Workers via Cron
Laravel SMTP Configuration (.env)
MAIL_MAILER=smtp
MAIL_HOST=mail.yourdomain.com
MAIL_PORT=465
MAIL_USERNAME=info@yourdomain.com
MAIL_PASSWORD=YourPassword
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS="info@yourdomain.com"Why Use Queue Workers for Email?
Synchronous email dispatch slows down user requests. Moving emails to background queues ensures instantaneous UI responses.
Database Queue Driver Setup
- Set
QUEUE_CONNECTION=databasein.env. - Run migrations:
php artisan queue:table && php artisan migrate
Scheduled Queue Worker via cPanel Cron
Run the worker every minute with automatic termination when jobs finish:
* * * * * cd /home/user/laravel_app && php artisan queue:work --stop-when-empty --tries=3 > /dev/null 2>&1
Was this helpful?
Thanks for your feedback!