framework: Laravel 11 with symfony/mailer v7.2.0 - UnsupportedSchemeException for SMTP configuration
Laravel Version
11.34.2
PHP Version
8.3.14
Database Driver & Version
No response
Description
After upgrading Laravel 8 -> 9 -> 10 -> 11, I noticed that it threw error when trying to send an email.
> \Mail::raw('Test email', function ($message) {
$message->to('...')->subject('Test Email');
});
Symfony\Component\Mailer\Exception\UnsupportedSchemeException The "" scheme is not supported; supported schemes for mailer "smtp" are: "smtp", "smtps".
I verified that mail config (smtp transport) was correct.
> config('mail.mailers.smtp');
= [
"transport" => "smtp",
... redacted ...
]
> config('mail');
= [
"default" => "smtp",
"mailers" => [
"smtp" => [
"transport" => "smtp",
When I upgraded to Laravel 11, Composer installed symfony/mailer with version 7.2.0.
I checked what my other Laravel 11 project had - it was 7.0.7.
So I tried to downgrade from 7.2.0 to 7.0.7, it did not throw error and I was able to send/receive email.
"require": {
...
"symfony/mailer": "7.0.7",
"laravel/framework": "^11.0",
...
}
> \Mail::raw('Test email', function ($message) {
$message->to('...')->subject('Test Email');
});
= Illuminate\Mail\SentMessage {#5336}
composer show symfony/mailer
name : symfony/mailer
descrip. : Helps sending emails
keywords :
versions : * v7.2.0
released : 2024-11-25, this week
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://symfony.com
source : [git] https://github.com/symfony/mailer.git e4d358702fb66e4c8a2af08e90e7271a62de39cc
dist : [zip] https://api.github.com/repos/symfony/mailer/zipball/e4d358702fb66e4c8a2af08e90e7271a62de39cc e4d358702fb66e4c8a2af08e90e7271a62de39cc
path : /.../app/vendor/symfony/mailer
names : symfony/mailer
support
source : https://github.com/symfony/mailer/tree/v7.2.0
autoload
psr-4
Symfony\Component\Mailer\ => .
exclude-from-classmap
requires
egulias/email-validator ^2.1.10|^3|^4
php >=8.2
psr/event-dispatcher ^1
psr/log ^1|^2|^3
symfony/event-dispatcher ^6.4|^7.0
symfony/mime ^7.2
symfony/service-contracts ^2.5|^3
requires (dev)
symfony/console ^6.4|^7.0
symfony/http-client ^6.4|^7.0
symfony/messenger ^6.4|^7.0
symfony/twig-bridge ^6.4|^7.0
conflicts
symfony/http-client-contracts <2.5
symfony/http-kernel <6.4
symfony/messenger <6.4
symfony/mime <6.4
symfony/twig-bridge <6.4
composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^8.2",
"barryvdh/laravel-dompdf": "^2.2",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^11.0",
"laravel/tinker": "^2.0",
"maatwebsite/excel": "^3.1",
},
"require-dev": {
"fakerphp/faker": "*",
"laravel/pint": "^1.5",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^8.1",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "stable",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
}
Steps To Reproduce
- Install Laravel 11
- Check that Composer installed symfony/mailer v7.2.0 or latest
- Try send email with smtp transport configured
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 23 (4 by maintainers)
Commits related to this issue
- Fix mailing issue (known issue for laravel/framework/issues/53721) — committed to mollevi/molnarfemmuvek-laravel by mollevi 2 years ago
When installing mailpit with Laravel Sail, .env is set with
MAIL_ENCRYPTION=null, which seems to cause this error.As others have said, changing it to
MAIL_ENCRYPTION=tlswill solve the problem.A fix has been merged and pending a release (https://github.com/laravel/framework/pull/53585). You should run
composer require "symfony/mailer:~7.1.0"until the release.Downgrading didn’t work for me but setting ‘scheme’ to ‘smtp’ in config ‘mailers.smtp’ did.
If you’re curious why this solution works, the code responsible for creating smtpTransport from
vendor\laravel\framework\src\Illuminate\Mail\MailManager.php:The scheme will default to
smtporsmtpsifencryption=tlsis specified in your configuration:Also, check your .env file to ensure the encryption value is set correctly. For example, in my case, I have:
env
If you need a different encryption type, you will need to manually specify the scheme value. To do so, check your
config/mail.phpfile to see if the scheme key is present. If not, add it:downgrading worked, but also adding the scheme key without downgrading worked
Thanks! @mathiaswillburger it’s working.
v7.1.6 works for me
This fixed my ISSUE. Thanks
I have a project wich was upgraded from laravel 6 to 11, my config/mail.php doesn’t have a “mailers.smtp” key, so I notice if we add the key just like:
`/* |-------------------------------------------------------------------------- | E-Mail Encryption Protocol |-------------------------------------------------------------------------- | | Here you may specify the encryption protocol that should be used when | the application send e-mail messages. A sensible default using the | transport layer security protocol should provide great security. | */
`
fixes the issue, in case someone has to deal with a similar issue.
To fix the probleme, in the config file mail.php, add the following to the smtp mailer :
ci does that usually, but I’ll give it a test, good idea.
Try
composer clear-cacheand/orphp artisan optimize:clear