# Configuring Laravel SMTP Email and Queue Workers via Cron

https://bihostnet.com/en/knowledgebase/article/laravel-smtp-email-queue-worker-cron-setup

## 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

1. Set `QUEUE_CONNECTION=database` in `.env`.
2. 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
```
