7

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
}
gp_sflover
  • 3,460
  • 5
  • 38
  • 48
Uğur Arıcı
  • 1,180
  • 1
  • 10
  • 16
  • 2
    Hi, I had the same problem after upgrade to laravel 9, but installing "symfony/mailgun-mailer" package solved it. Did you try composer dump-autoload afterwards, to clear autoload cache? – Tomáš Mleziva Mar 21 '22 at 12:09

2 Answers2

17

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

Oleg Olegovich
  • 250
  • 1
  • 6
8

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.

Uğur Arıcı
  • 1,180
  • 1
  • 10
  • 16
  • Wow. A restart solved the issue in my case, as mentioned in your comment, which I would never think of. I'm not using Laravel Octane, but it helped. Thanks! – azurecorn Aug 15 '23 at 01:39