mardi 26 septembre 2017

Getting Unauthorized error trying to send email with Sparkpost (Laravel 5.4)

I've been following the Laravel Mail docs http://ift.tt/2o4SyIX to send email via a SparkPost account. When I try and send I'm getting

ClientException
Client error: `POST http://ift.tt/1xBMTcd` resulted in a `401 Unauthorized` response:
{"errors": [ {"message": "Unauthorized."} ]}

As per the docs I've got the sparkpost key in config/services.php and though the docs don't mention anything about it (why not!?) a bit of Googling convinced me to set the mail driver etc. in my .env file. I then have a web route to check the config being used,

Route::get('test', function()
{
    dd(Config::get('mail'));
});

which gives

array:9 [▼
  "driver" => "sparkpost"
  "host" => "smtp.sparkpostmail.com"
  "port" => "587"
  "from" => array:2 [▶]
  "encryption" => "tls"
  "username" => "my-sparkpost-account-login-email-address"
  "password" => "my-sparkpost-account-login-password"
  "sendmail" => "/usr/sbin/sendmail -bs"
  "markdown" => array:2 [▶]
]

I actually want to use a mailable and views which I've set up, but just to test the sending I bypassed these and set the following route to test:

Route::get('/sparkpost', function () {
  Mail::send('emails.test', [], function ($message) {
    $message
      ->from('marketing@my-sparkpost-sending-domain.com', 'Me')
      ->to('my-email-address', 'My-Name')
      ->subject('A Test Email');
  });
});

which got the error at the top (testing with my mailables and views gave the exact same error which makes me think they are correctly set up - assuming the above test route is correct).

The on thing I'm wondering about is I'm testing on my local machine, so test URL is http://localhost/seg/public/sparkpost - I'm wondering if this is tripping SparkPost up (i.e. do I have to actually be sending from a server running at the same domain as the sending domain configured in sparkpost, or is it just the sending address in the email that has to match?)

Thanks for any suggestions!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2wiJ64t
via IFTTT

Aucun commentaire:

Enregistrer un commentaire