Lumen Mailgun Integration Issue - Constructor Expects HttpClientConfigurator Instead of String

I’m working on a Lumen application and trying to integrate Mailgun for email functionality. After installing the mailgun-php package using composer, I’m running into a constructor error.

Installation command used:

composer require mailgun/mailgun-php kriswallsmith/buzz nyholm/psr7

My current implementation:

use Mailgun\Mailgun;
$mailgunClient = new Mailgun('api-key-12345678901234567');

Error message I’m getting:

Argument 1 passed to Mailgun\Mailgun::__construct() must be an instance of Mailgun\HttpClient\HttpClientConfigurator, string given

It seems like the constructor signature has changed and it no longer accepts a string API key directly. Has anyone encountered this issue before? What’s the correct way to initialize the Mailgun client now?

yep, they’ve updated it. now u gotta use the static method. just do $mailgunClient = Mailgun::create('your-api-key'); and it should fix the error. good luck!

Mailgun’s PHP library had a major update that changed how you create the client. You can’t just pass the API key to the constructor anymore - now you need HttpClientConfigurator:

use Mailgun\Mailgun;
use Mailgun\HttpClient\HttpClientConfigurator;

$configurator = new HttpClientConfigurator();
$configurator->setApiKey('your-api-key-here');
$mailgunClient = new Mailgun($configurator);

Or use the factory method - it’s cleaner since it handles configuration internally. I’ve found this way less error-prone.