π§ 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!