# Email Configuration Instructions

## Using Free Email Services with Laravel

This application includes email functionality to send invoices to customers. Below are instructions for configuring free email services.

---

## Option 1: Mailtrap (Recommended for Testing)
**Free Tier:** 100 emails/month

1. Sign up at [https://mailtrap.io](https://mailtrap.io)
2. Go to Email Testing → Inboxes
3. Click on your inbox and copy the SMTP credentials
4. Update your `.env` file:

```env
MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_mailtrap_username
MAIL_PASSWORD=your_mailtrap_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="noreply@yourstore.com"
MAIL_FROM_NAME="Amazon Store"
```

---

## Option 2: Gmail (For Production)
**Free Tier:** 500 emails/day

1. Enable 2-Factor Authentication on your Google Account
2. Generate an App Password:
   - Go to Google Account → Security → 2-Step Verification → App passwords
   - Create a new app password for "Mail"
3. Update your `.env` file:

```env
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_gmail@gmail.com
MAIL_PASSWORD=your_16_character_app_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="your_gmail@gmail.com"
MAIL_FROM_NAME="Amazon Store"
```

---

## Option 3: Mailgun (For Production)
**Free Tier:** 100 emails/day

1. Sign up at [https://www.mailgun.com](https://www.mailgun.com)
2. Verify your domain (or use sandbox domain for testing)
3. Get your API credentials from Settings → API Keys
4. Update your `.env` file:

```env
MAIL_MAILER=mailgun
MAILGUN_DOMAIN=your-domain.mailgun.org
MAILGUN_SECRET=your-api-key
MAILGUN_ENDPOINT=api.mailgun.net
MAIL_FROM_ADDRESS="noreply@yourdomain.com"
MAIL_FROM_NAME="Amazon Store"
```

---

## Option 4: SendGrid (For Production)
**Free Tier:** 100 emails/day

1. Sign up at [https://sendgrid.com](https://sendgrid.com)
2. Create an API Key: Settings → API Keys → Create API Key
3. Update your `.env` file:

```env
MAIL_MAILER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=your_sendgrid_api_key
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="noreply@yourdomain.com"
MAIL_FROM_NAME="Amazon Store"
```

---

## Testing Email Locally

For development/testing, you can use the `log` driver which writes emails to `storage/logs/laravel.log`:

```env
MAIL_MAILER=log
```

This is the default setting and doesn't send actual emails.

---

## How to Use Email Feature

1. Configure your `.env` file with one of the options above
2. Clear the config cache:
   ```bash
   php artisan config:clear
   ```
3. Go to any invoice detail page
4. Click the **📧 Email Invoice** button
5. Enter the recipient's email address
6. Click **Send Email**

The customer will receive a beautifully formatted invoice email with all order details!

---

## Troubleshooting

**Email not sending?**
- Check that your `.env` file is configured correctly
- Run `php artisan config:clear` after changing mail settings
- Check `storage/logs/laravel.log` for error messages
- Verify your email service credentials are correct
- For Gmail, make sure you're using an App Password (not your regular password)
- Check spam/junk folder if emails are not arriving

**Testing emails without sending?**
- Use Mailtrap - it catches all emails without delivering them
- Or use `MAIL_MAILER=log` to write emails to the log file
