Cannot send message without a sender address in laravel 5.2 I have set .env and mail.php both
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# Solving the Sender Address Error in Laravel Mail: A Deep Dive into Configuration Issues
As a senior developer working with frameworks like Laravel, you often encounter frustrating runtime errors that seem unrelated to the configuration you've meticulously set up. The error message you are seeing—`Swift_TransportException in AbstractSmtpTransport.php line 162: Cannot send message without a sender address`—is a classic SMTP delivery failure. Even when you have correctly populated your `.env` file and customized `mail.php`, this specific issue usually points to a subtle misconfiguration within the mail transport layer, particularly concerning how the "From" address is defined for the outgoing message.
This post will dissect why this error occurs, analyze your provided configuration, and walk you through the exact steps needed to resolve this issue, ensuring robust email delivery in your Laravel application.
## Understanding the SMTP Sender Requirement
When an application attempts to send an email via an SMTP server (like Gmail, Outlook, or a custom mail service), the SMTP protocol strictly requires that the sender address (`MAIL FROM`) be explicitly defined. If the configuration lacks this mandatory piece of information, the transport layer rejects the connection immediately, resulting in the `Swift_TransportException`.
You mentioned you have set your environment variables and customized `mail.php`, yet the error persists. This strongly suggests an issue with how Laravel is interpreting or applying the sender details within the mail setup, especially when mixing environment variable access and array definitions.
## Analyzing Your Configuration Setup
Let's examine the configuration snippets you provided:
**Your `.env` file:**
```env
MAIL_DRIVER=smtp
MAIL_HOST=smtp-mail.outlook.com
MAIL_PORT=587
MAIL_USERNAME=raval_himanshu@live.in
MAIL_PASSWORD=pass
MAIL_ENCRYPTION=tls
```
**Your `mail.php` configuration:**
```php
'from' => ['raval_himanshu@live.in' => null, 'Himanshu Raval' => null],
'username' => 'raval_himanshu@live.in',
// ... other settings
```
The problem often lies in the structure of the `'from'` array. While you have defined it, setting values to `null` might confuse the underlying mailer mechanism expecting a direct string or a properly formatted address for the primary sender. Furthermore, defining both an email and a display name within this structure needs careful handling depending on how the specific SMTP library processes it.
## Step-by-Step Solution and Best Practices
Since caching (`php artisan config:cache`) did not resolve the issue, we need to focus on ensuring the configuration is loaded correctly and that the sender address format is unambiguous.
### 1. Simplify the 'From' Address Configuration
For most standard SMTP setups, you only need a single, valid email address for the `from` field. Remove the complex array structure and ensure it holds a single string representing the actual sending address.
**Recommended Change in `mail.