Search code examples
phplaravelapilumenmailgun

Mailgun error in Lumen - Argument 1 passed to Mailgun\Mailgun::__construct()


I've installed Mailgun-php in my Lumen project. ( https://github.com/mailgun/mailgun-php )

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

My codes something like this :

use Mailgun\Mailgun;
$mg = new Mailgun('key-xxxxxxxxxxxxxxxxx');

error:

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

Did anyone solve this problem?

Thank you.


Solution

  • You haven't actually read the docs for the library you're using.

    use Mailgun\Mailgun;
    
    $mg = Mailgun::create('key-example');
    

    You need to call Mailgun::create(), not create a new instance of Mailgun.

    It's worth noting that Lumen still supports Laravel's mail implementation, so you could still use that instead of requiring Mailgun directly (if that supported your use-case).