# Quick Email Testing Guide

## How to Test if Email System is Working

### Method 1: Check Logs (Fastest)

1. Open terminal/command prompt
2. Navigate to project root:
   ```bash
   cd c:\Users\Admin\Downloads\will 12032026\will2105\will-fwg
   ```

3. Check the last 5 lines of log for email activities:
   ```bash
   # Windows PowerShell
   Get-Content -Tail 5 storage/logs/laravel.log | Select-String "email"
   
   # Or use raw output
   Get-Content -Tail 100 storage/logs/laravel.log | findstr /i "email sent failed"
   ```

### Method 2: Create Test Agent/Lawyer

1. Go to Admin Panel → Staff Management
2. Click "Add Staff"
3. Fill in form with test data:
   - Name: Test Agent
   - Email: **use a test email you can check** (e.g., your personal email)
   - Role: Agent
   - Password: TestPass123456
4. Click "Create Staff"
5. **Watch the log file in real-time**:
   ```bash
   # PowerShell - watch logs continuously
   Get-Content storage/logs/laravel.log -Wait | Select-String "email"
   ```

### Method 3: Check Email in Multiple Places

After creating agent/lawyer, check:
1. **Inbox** - Main email folder
2. **Spam/Junk** - Very likely location if SPF/DKIM/DMARC not set
3. **Promotions Tab** - If using Gmail
4. **Other Tabs** - If using Gmail

### Expected Email

**From**: info@dextratechnologies.com (FWG Trustees Admin)  
**Subject**: Welcome to FWG Trustees - Your Agent Account is Ready  
**Content**: Professional HTML email with:
- FWG Trustees logo and branding
- Congratulations message
- Role information
- Email login credential (the email they used)
- Temporary password (the one you entered)
- How to reset password
- Support information

## What to Do If Email is NOT Received

### Step 1: Check Logs for Errors
```bash
Get-Content storage/logs/laravel.log | Select-String -Pattern "Failed to send|error" | Select-Object -Last 10
```

### Step 2: Check Configuration
Verify `.env` file has correct settings:
```env
MAIL_MAILER=smtp
MAIL_HOST=smtpout.secureserver.net
MAIL_PORT=587
MAIL_USERNAME=info@dextratechnologies.com
MAIL_PASSWORD=Trickz2know@DXT2026*&^
MAIL_ENCRYPTION=tls
```

### Step 3: Clear Laravel Cache
Sometimes Laravel caches old configuration:
```bash
php artisan config:cache
php artisan cache:clear
php artisan view:clear
```

Then test again by creating a new agent/lawyer.

### Step 4: Check if Email in Spam
If email appears in spam folder:
1. Mark as "Not Spam" 
2. Need to add DNS records for SPF/DKIM/DMARC (see EMAIL_SPAM_FIX_GUIDE.md)

### Step 5: Restart Services
If none of above works:
1. Stop Laravel development server (if running)
2. Restart web server (Apache/Nginx)
3. Test again

## Common Issues & Solutions

| Issue | Cause | Solution |
|-------|-------|----------|
| Email not sent, log shows "tls scheme not supported" | Old cached config | Run `php artisan config:cache && php artisan cache:clear` |
| Email sent but in SPAM folder | Missing DNS records | Add SPF/DKIM/DMARC to domain (see EMAIL_SPAM_FIX_GUIDE.md) |
| Email not received at all | Wrong email in form | Check you entered email correctly in admin form |
| Password not working | Wrong temporary password used | Use exact password from admin creation form |
| SMTP connection failed | Wrong SMTP credentials | Verify .env MAIL_USERNAME and MAIL_PASSWORD |

## Success Indicators

✅ Email system is working if:
1. Log shows: `local.INFO: Onboarding email sent to [name] ([email])`
2. Email received in inbox within 2-5 minutes
3. Email contains all expected information
4. Password/credentials work on login

## Still Not Working?

**Debug Step**: Add test route to manually send email

1. Open `routes/web.php`
2. Add temporary test route (for debugging only):
   ```php
   Route::get('/debug-email', function() {
       $testUser = \App\Models\User::where('role', 'agent')->first();
       if (!$testUser) {
           return 'No agent found to test with';
       }
       try {
           \Mail::to('YOUR-EMAIL@example.com')->send(
               new \App\Mail\OnboardingNotification($testUser, 'TestPassword123')
           );
           return 'Email sent! Check logs at storage/logs/laravel.log';
       } catch (\Exception $e) {
           return 'Error: ' . $e->getMessage();
       }
   });
   ```
3. Visit: `http://localhost/debug-email`
4. Check logs and email

---

**Next**: If email is working, verify it's not going to spam. If in spam, follow EMAIL_SPAM_FIX_GUIDE.md
