Bogardo / Mailgun

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

Clarification please regarding handling of http_response_body content and possibly guzzle and/or env setting? #140

Closed jaltfeld closed 6 years ago

jaltfeld commented 6 years ago

Hi @Bogardo and/or anyone who can help,

I installed Bogardo/Mailgun (with "php-http/guzzle6-adapter": "^1.1") to my Laravel 5.3 project according to the github instructions at the time of this message, BUT only after installing mailgun/mailgun-php (with "guzzlehttp/psr7": "^1.4" and "guzzlehttp/guzzle": "^6.3")...

Initially I was using the $mg->messages()->send($domain, $params); functionality of the mailgun/mailgun-php package, which was working fine and sending basic text emails, but eventually I wanted to send an actual email view via Laravel's "send()" method as Bodargo/Mailgun utilizes. So I went ahead and installed it as outlined by the read-me.

I had a hard time importing the package with the "use" statement at first but eventually realized that the service provider alias allowed me to simply say "use Mailgun" - then my errors began to change and eventually I ended up getting the following error...

"Trying to get property of non-object" on line 37 of ".../vendor/bogardo/mailgun/src/Http/Response.php"

..this line is setting $this->message = $response->http_response_body->message; only my problem is that I was getting back "Mailgun Magnificent API" as my http_response_body where the package is expecting an object with a "message" property - I realize this may be due to my own configuration settings either locally or in my mailgun account - however my emails were sending with the mailgun/mailgun-php package so I'm guessing my mailgun account settings must be okay...

However when you bind the guzzle adapter to the application in the AppServiceProvider.php - the instructions seem to suggest that you apply your guzzle settings here - I left this section empty because I never had to specify with the mailgun/mailgun-php package (which isn't Bogardo/Mailgun built on?) - and everything sent just fine.

public function register()
    {
        $this->app->bind('mailgun.client', function() {
            return \Http\Adapter\Guzzle6\Client::createWithConfig([
                // your Guzzle6 configuration
            ]);
        });
    }

Is this the reason for my getting the wrong response?

Also when I modify that line to $this->message = $response->http_response_body; I get back no error but nothing happens and the mailgun dash reflects no activity whatsoever - so there's another clue.

I'm also wondering is it possible that I could have something missing from my .env settings (I also did NOT set any settings in the generated "config/mailgun.php" file - I figured the .env was enough) - my mail related settings there are as follows...

######### BEGIN MAIL SPECS HERE ##########

MAIL_DRIVER=mailgun

MAILGUN_SECRET=myprivatekey 
###above setting leftover from mailgun/mailgun-php package

# Domain name registered with Mailgun
MAILGUN_DOMAIN=sandboxABC123.mailgun.org

# Mailgun (private) API key
MAILGUN_PRIVATE=myprivatekey

# Mailgun public API key
MAILGUN_PUBLIC=mypublickey

# You may wish for all e-mails sent with Mailgun to be sent from
# the same address. Here, you may specify a name and address that is
# used globally for all e-mails that are sent by this application through Mailgun.
MAILGUN_FROM_ADDRESS=me@mywebsite.com 
###I read somewhere that leaving the above setting empty could contribute to receiving the "Mailgun Magnificent API" response - I'd actually rather leave this blank and just specify in the from address in the Laravel send() method...
MAILGUN_FROM_NAME=

# Global reply-to e-mail address
MAILGUN_REPLY_TO=

# Force the from address
#
# When your `from` e-mail address is not from the domain specified some
# e-mail clients (Outlook) tend to display the from address incorrectly
# By enabling this setting, Mailgun will force the `from` address so the
# from address will be displayed correctly in all e-mail clients.
#
# WARNING:
# This parameter is not documented in the Mailgun documentation
# because if enabled, Mailgun is not able to handle soft bounces
MAILGUN_FORCE_FROM_ADDRESS=

# Testing
# 
# Catch All address
#
# Specify an email address that receives all emails send with Mailgun
# This email address will overwrite all email addresses within messages
MAILGUN_CATCH_ALL=

# Testing
# 
# Mailgun's testmode
#
# Send messages in test mode by setting this setting to true.
# When you do this, Mailgun will accept the message but will
# not send it. This is useful for testing purposes.
#
# Note: Mailgun DOES charge your account for messages sent in test mode.
MAILGUN_TESTMODE=

######### END MAIL SPECS HERE ##########

...also if it helps I have the following packages installed on this project...

"require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",
        "dingo/api": "1.0.0Beta6",
        "tymon/jwt-auth": "0.5.*",
        "intervention/image": "^2.4",
        "doctrine/dbal": "^2.5",
        "guzzlehttp/guzzle": "^6.3",
        "mailgun/mailgun-php": "^2.4",
        "php-http/guzzle6-adapter": "^1.1",
        "guzzlehttp/psr7": "^1.4",
        "bogardo/mailgun": "^5.0"
    },

Any suggestions on the matter would be greatly appreciated - I'd really like to use this package to send html emails via Laravel blade views - rather then regular text emails with the other mailgun/mailgun-php package

...but right now that's all that I can get to work - anybody got any pointers??

Thanks ahead of time! -jaltfeld

csimpi commented 6 years ago

I'm getting the same, I guess Mailgun response structure has been changed in the meantime. Is this an abandoned project? I can't get it to work at all.

csimpi commented 6 years ago

@jaltfeld I've got the answer here: https://github.com/Bogardo/Mailgun/issues/144#issuecomment-403428850

jaltfeld commented 6 years ago

@csimpi Hey thanks a lot for looping me in on that answer - I ended up moving on from the bogardo mailgun package for a more hand made workaround a while back but if I end up working with it again (which I may, now that you've given me this piece of information), then I'll know the genuine solution - thanks!