Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 11 with symfony/mailer v7.2.0 - UnsupportedSchemeException for SMTP configuration #53721

Closed
matbcvo opened this issue Dec 1, 2024 · 23 comments

Comments

@matbcvo
Copy link

matbcvo commented Dec 1, 2024

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

  1. Install Laravel 11
  2. Check that Composer installed symfony/mailer v7.2.0 or latest
  3. Try send email with smtp transport configured
@matbcvo matbcvo changed the title Laravel 11 with symfony/mailer v7.2.0 Laravel 11 with symfony/mailer v7.2.0 - UnsupportedSchemeException for SMTP configuration Dec 1, 2024
@ahinkle
Copy link
Contributor

ahinkle commented Dec 1, 2024

Symfony Mailer 7.2 isn't supported. However, a PR was recently merged. #53585

@crynobone
Copy link
Member

A fix has been merged and pending a release (#53585). You should run composer require "symfony/mailer:~7.1.0" until the release.

@McTom234
Copy link

McTom234 commented Dec 1, 2024

@crynobone So we downgraded manually, but the issue still exists with version 7.1.6.

@matbcvo
Copy link
Author

matbcvo commented Dec 1, 2024

> composer show symfony/mailer
name     : symfony/mailer
descrip. : Helps sending emails
keywords :
versions : * v7.1.6

v7.1.6 works for me

@McTom234
Copy link

McTom234 commented Dec 1, 2024

(ssh) ❯ sudo -u www-data composer show symfony/mailer
name     : symfony/mailer
descrip. : Helps sending emails
keywords : 
versions : * v7.1.6

Does still not work for me. the config file:

'mailers' => [
    'smtp' => [
        'transport' => 'smtp',
        'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
        'port' => env('MAIL_PORT', 587),
        'encryption' => env('MAIL_ENCRYPTION', 'tls'),
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
        'timeout' => null,
    ],
],

env:

MAIL_DRIVER=smtp
# MAIL_HOST, MAIL_PORT, username, password etc
MAIL_ENCRYPTION=ssl

error: production.ERROR: The "" scheme is not supported; supported schemes for mailer "smtp" are: "smtp", "smtps".

@matbcvo
Copy link
Author

matbcvo commented Dec 1, 2024

Try composer clear-cache and/or php artisan optimize:clear

@McTom234
Copy link

McTom234 commented Dec 1, 2024

ci does that usually, but I'll give it a test, good idea.

@noBasics
Copy link

noBasics commented Dec 1, 2024

hey, had the same issue here and downgrading to symfony/mailer 7.1.6 fixes it

@hafidm93
Copy link

hafidm93 commented Dec 2, 2024

got same issue, I solve by downgrading to 7.1.6

@daniellesniak
Copy link

daniellesniak commented Dec 2, 2024

Downgrading didn't work for me but setting 'scheme' to 'smtp' in config 'mailers.smtp' did.

        'smtp' => [
            'scheme' => 'smtp', // smtp or smtps

            'transport' => 'smtp',
            'url' => env('MAIL_URL'),
            'host' => env('MAIL_HOST', '127.0.0.1'),
            'port' => env('MAIL_PORT', 2525),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url(env('APP_URL', 'http://localhost'), PHP_URL_HOST)),
        ],

If you're curious why this solution works, the code responsible for creating smtpTransport from vendor\laravel\framework\src\Illuminate\Mail\MailManager.php:

    protected function createSmtpTransport(array $config)
    {
        $factory = new EsmtpTransportFactory;

        $scheme = $config['scheme'] ?? null;

        if (! $scheme) {
            $scheme = ! empty($config['encryption']) && $config['encryption'] === 'tls'
                ? (($config['port'] == 465) ? 'smtps' : 'smtp')
                : ''; // here
        }

        $transport = $factory->create(new Dsn(
            $scheme,
            $config['host'],
            $config['username'] ?? null,
            $config['password'] ?? null,
            $config['port'] ?? null,
            $config
        ));

        return $this->configureSmtpTransport($transport, $config);
    }

@dzandrey
Copy link

dzandrey commented Dec 2, 2024

The scheme will default to smtp or smtps if encryption = tls is specified in your configuration:

'smtp' => [
    //....
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'port' => env('MAIL_PORT', 587),
],

Also, check your .env file to ensure the encryption value is set correctly. For example, in my case, I have:

env

MAIL_ENCRYPTION=tls

If you need a different encryption type, you will need to manually specify the scheme value. To do so, check your config/mail.php file to see if the scheme key is present. If not, add it:

'smtp' => [
    //....
    'scheme' => env('MAIL_SCHEME', 'smtp'), // smtp or smtps
],

@faiare
Copy link

faiare commented Dec 3, 2024

When installing mailpit with Laravel Sail, .env is set with MAIL_ENCRYPTION=null, which seems to cause this error.

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

As others have said, changing it to MAIL_ENCRYPTION=tls will solve the problem.

@ford555
Copy link

ford555 commented Dec 3, 2024

Same error for me and downgrading to v1.7.6 works for me.

composer show symfony/mailer
name : symfony/mailer
descrip. : Helps sending emails
keywords :
versions : * v7.1.6

Waiting for (A fix has been merged and pending a release (#53585)

@ford555
Copy link

ford555 commented Dec 3, 2024

ci does that usually, but I'll give it a test, good idea.

you have to change MAIL_DRIVER to MAIL_MAILER in your .env file

@mathiaswillburger
Copy link

downgrading worked, but also adding the scheme key without downgrading worked

'smtp' => [
    //....
    'scheme' => env('MAIL_SCHEME', 'smtp'), // smtp or smtps
],

@bilal-techmave
Copy link

downgrading worked, but also adding the scheme key without downgrading worked

'smtp' => [
    //....
    'scheme' => env('MAIL_SCHEME', 'smtp'), // smtp or smtps
],

Thanks! @mathiaswillburger it's working.

@nsommer89
Copy link

I got the same error today, when I did:

Mail::raw('test mail hello', function($msg) {$msg->to('test@test.com')->subject('Just a test'); });

I got this...
Symfony\Component\Mailer\Exception\UnsupportedSchemeException The "" scheme is not supported; supported schemes for mailer "smtp" are: "smtp", "smtps".

The solution was to change the .env file.....
MAIL_ENCRYPTION=tls

But that was setting up mailhog.

@losada24
Copy link

losada24 commented Dec 4, 2024

downgrading worked, but also adding the scheme key without downgrading worked

'smtp' => [
    //....
    'scheme' => env('MAIL_SCHEME', 'smtp'), // smtp or smtps
],

Thanks! @mathiaswillburger it's working.

This fixed my ISSUE. Thanks

@TCM-RAN
Copy link

TCM-RAN commented Dec 6, 2024

To fix the probleme, in the config file mail.php, add the following to the smtp mailer :

    'mailers' => [
        'smtp' => [
            'scheme' => 'smtp',
    .....

@rcapulsuhay
Copy link

downgrading worked, but also adding the scheme key without downgrading worked

'smtp' => [
    //....
    'scheme' => env('MAIL_SCHEME', 'smtp'), // smtp or smtps
],

this works! but do not add MAIL_SCHEME on the env file, it will show the error again

@MuscledGeek
Copy link

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.
|
*/

'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'scheme' => 'smtp', // <--- add here

`

fixes the issue, in case someone has to deal with a similar issue.

@sts-ryan-holton
Copy link
Contributor

Still getting the error for mailpit even when setting encryption to tls and defining smtp mailer

@Khuthaily
Copy link

I have just submitted a PR. There is no need to downgrade. You can simply define MAIL_SCHEME=smtp in your .env file, or modify the smtp mailer settings in your config/mail.php file to 'scheme' => env('MAIL_SCHEME', 'smtp').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests