You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sending a Mailable with an envelope without the from argument throws an error, even when a global from address is set in the config.
I seems that as long as an envelope is defined, Laravel tries to get the sender address from it without defaulting to the config sender.
Attempt to read property "address" on null
at vendor/laravel/framework/src/Illuminate/Mail/Mailables/Envelope.php:272
268▕ */
269▕ public function isFrom(string $address, string $name = null)
270▕ {
271▕ if (is_null($name)) {
➜ 272▕ return $this->from->address === $address;
273▕ }
274▕
275▕ return $this->from->address === $address &&
276▕ $this->from->name === $name;
Explicitly setting the from argument to the config value fixes the issue but it would be better to rely on the implicit global configuration as stated in the documentation.
Steps To Reproduce
Mailable:
<?phpnamespaceApp\Mail;
useIlluminate\Bus\Queueable;
useIlluminate\Mail\Mailable;
useIlluminate\Mail\Mailables\Content;
useIlluminate\Mail\Mailables\Envelope;
useIlluminate\Queue\SerializesModels;
class PasswordReset extends Mailable
{
use Queueable;
use SerializesModels;
/** * Create a new message instance. */publicfunction__construct(protectedstring$url)
{
}
/** * Get the message envelope. */publicfunctionenvelope(): Envelope
{
returnnewEnvelope(
subject: 'Password Reset',
);
}
/** * Get the message content definition. */publicfunctioncontent(): Content
{
returnnewContent(
view: 'emails.resetPassword',
with: [
'url' => $this->url,
]
);
}
}
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
The assertion is made on the Mailable instance and checks the from parameter on the envelope. Since the envelope has no from defined, it throws an error down the line.
It only affects tests, so definitely not a big deal. I'm not even sure this is really a bug. I guess it could be handled better and not throw an error but that's it.
Laravel Version
10.45.1
PHP Version
8.1.27
Database Driver & Version
No response
Description
Sending a Mailable with an envelope without the
from
argument throws an error, even when a globalfrom
address is set in the config.I seems that as long as an envelope is defined, Laravel tries to get the sender address from it without defaulting to the config sender.
Explicitly setting the
from
argument to the config value fixes the issue but it would be better to rely on the implicit global configuration as stated in the documentation.Steps To Reproduce
Mailable:
config/mail.php:
Method that sends the email:
The text was updated successfully, but these errors were encountered: