Skip to main content

πŸ“§ Testing Mail Functionality in Laravel

πŸ”§ Step 1: Navigate to Your Project Directory​

Change to the directory where your Laravel project is located:

cd /path/to/your/laravel/project

πŸ’» Step 2: Enter Laravel Tinker​

Laravel Tinker provides an interactive REPL for your application. Use it to run commands and test functionality:

php artisan tinker

βœ‰οΈ Step 3: Send a Test Email​

Once inside Tinker, use the Mail facade to send a test email. Replace [email protected] with the email address where you want to receive the test message:

Mail::raw('Hello World!', function($msg) {
$msg->to('[email protected]')->subject('Test Email');
});

πŸ› οΈ Additional Tips​

βœ… Configuration Check​

Make sure your .env file is correctly configured:

MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"

πŸ” Tip: If using Gmail, make sure to enable "Less secure app access" or use an App Password.

πŸ§ͺ Testing Locally​

If you're testing on a local machine, tools like Mailtrap 🧲 are great for capturing outgoing emails without sending them to real addresses.

πŸ“œ Logs and Errors​

Check Laravel logs if something goes wrong:

tail -f storage/logs/laravel.log

🧾 This log file will help you debug any email-related errors or misconfigurations.


πŸŽ‰ That’s it! You’ve now learned how to test email functionality using Laravel Tinker. Great for debugging and verifying your email setup!