Bogardo / Mailgun

Mailgun package for Laravel
MIT License
295 stars 116 forks source link

Troubles with the API request, deprecated usable of mailgun-php lib #144

Open csimpi opened 6 years ago

csimpi commented 6 years ago

It seems this project has been abandoned and doesn't really works with the new version of mailgun api. I'm not sure about this, but I couldn't make it work, I'm getting Mailgun Magnificent API response after any API request that this wrapper sends through Mailgun API.

I modified the package on my local and added some debugging, the configuration seems to be okay.

When I opened the https://github.com/Bogardo/Mailgun/blob/master/src/Mail/Mailer.php file I realized, this wrapper uses deprecated methods, so I suppose this causes the Trying to get property of non-object" on line 37 of .../vendor/bogardo/mailgun/src/Http/Response.php error, since the wrong request generates a reponse that not has message property.

Everybody who would like to use the mailgun-php (https://github.com/mailgun/mailgun-php) client with Laravel project can implement and use the original package with adding this line to the /config/app.php file to the aliases array: 'Mailgun' => Mailgun\Mailgun::class,

then you will be able to use original mailgun-php client's functions, like:

        $mg = Mailgun::create(env('MAILGUN_PRIVATE'));
        $dns = $mg->domains()->show(env('MAILGUN_DOMAIN'))->getInboundDNSRecords();
        dump($dns);

I removed bogardo/mailgun wrapper composer remove bogardo/mailgun Installed mailgun and guzzle adapter composer require mailgun/mailgun-php composer require php-http/guzzle6-adapter

azwel commented 6 years ago

@csimpi this project does work. The response Trying to get property of non-object" on line 37 of .../vendor/bogardo/mailgun/src/Http/Response.php is caused by invalid config settings from config/mailgun.php file which by default seems not to utilize the .env settings. Quick fix:

    /*
     * Domain name registered with Mailgun
     *
     */
    'domain' => env('MAILGUN_DOMAIN'),

    /*
     * Mailgun (private) API key
     *
     */
    'api_key' => env('MAILGUN_PRIVATE'),

    /*
     * Mailgun public API key
     *
     */
    'public_api_key' => env('MAILGUN_PUBLIC'),

and everything works fine!

Edit:

That's strange... the config in the repository does contain reading from .env however the one that published using publish command doesn't!

csimpi commented 6 years ago

Great news! Thank you for the clarification. I added the details to the env file only as the documentation says. I supposed those vars are coming directly from the env file, not through the mailgun config file.

I think you should change the documentation about the default/published config file difference, there are a couple of similar tickets regarding this issue, without any answer.

Finally, I'm going to use the raw mailgun-php package in Laravel since that's easier to use with the mailgun official documentation, but I wanna say thank you for your work and the solution also.