Class "Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory" not found on Laravel 9

Viewed 2164

I just wanted to use Mailgun to send E-mail from my Laravel project and followed this steps from official document: https://laravel.com/docs/9.x/mail#mailgun-driver

composer require symfony/mailgun-mailer symfony/http-client

When I try to send password reset e-mail to test it, it throws an excepiton:

Class "Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory" not found

Here is the full stack trace: https://flareapp.io/share/oPRKqyZ7#share

I don't know but maybe it's because this project started as a Laravel 8 project and I updated it to Laravel 9 one week ago. Is it trying to find something comes with Laravel 9 into app directory or something but my project doesn't have that? I didn't understand.

By the way if it helps; this project uses Jetstream with Inertia.js and Vue.js. So the composer.json looks like this now:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0.2",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.2",
        "inertiajs/inertia-laravel": "^0.5.4",
        "laravel/framework": "^9.2",
        "laravel/jetstream": "^2.4",
        "laravel/octane": "^1.0",
        "laravel/sanctum": "^2.14.1",
        "laravel/tinker": "^2.7",
        "sentry/sentry-laravel": "^2.11",
        "symfony/http-client": "^6.0",
        "symfony/mailgun-mailer": "^6.0",
        "tightenco/ziggy": "^1.0"
    },
    "require-dev": {
        "spatie/laravel-ignition": "^1.0",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.12",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.5.10"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
2 Answers

From the upgrade guide:

To continue using the Mailgun transport, your application should require the symfony/mailgun-mailer and symfony/http-client Composer packages:

so use:

composer require symfony/mailgun-mailer symfony/http-client

More information here Upgrade to laravel 9

Apparently it was something with Laravel Octane which I use on my project. I already ran composer require symfony/mailgun-mailer symfony/http-client and composer auto-dump etc and restart my processes on Supervisor but nothing changed. In the and I killed all processes (including supervisor, which keeps Laravel Octane alive) and then restarted them.

I think Laravel Octane wasn't able to load renewed composer autoload files. When everything stopped and restarted, they just worked well.

Related