0

I am using this guide as a reference to set up Sparkpost Mailer in local server for my Laravel app but I am getting this error whenever I try to send a mail. I have also tried to copy using the same exact settings as the guide but I still get the same error.But its working fine for sparkpost sandbox domain.

SparkPostException in SparkPost.php line 103: { "errors": [ { "message": "Invalid domain", "description": "No sending domain specified", "code": "7001" } ] }

My account sending domain status is verified but it shows this above error.

My domain screen shot is:enter image description here

My email sending function is:

public function sendEmail($to,$subject,$messageBody){
        $httpClient = new GuzzleAdapter(new Client());
        $sparky = new SparkPost($httpClient['key'=>env('SPARKPOST_SECRET')]);
       $sparky->setOptions(['async' => false]);
        $promise = $sparky->request('GET', 'metrics/ip-pools', [
            'from' => '2014-12-01T09:00',
            'to' => '2015-12-01T08:00',
            'timezone' => 'America/New_York',
            'limit' => '10',
        ]);
        $promise = $sparky->transmissions->post([
           'options' => [
            'sandbox' => false,
            'open_tracking'=> true,
            'click_tracking'=> true,
            'transactional'=> true,
            ],
            'content' => [
                'from' => [
                    'name' => 'SparkPost Team',
                    'email' => 'test@dskmail.com',
                ],
                'subject' => $subject,
                'html' => $messageBody,
                'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!',
            ],
            'substitution_data' => ['name' => 'ashraf'],
            'recipients' => [
                [
                    'address' => [
                        'name' => 'Test',
                        'email' => $to,
                    ],
                ],
            ],

        ]);

    }
Grokify
  • 15,092
  • 6
  • 60
  • 81
  • Is that exactly the code you are using? If you have an empty from address (just the double quotes with no actual address) you will get that error. – Yepher Dec 26 '17 at 21:16
  • @Yepher i used a verified send domain that i attach but it show this error.It can be happened for api key or Local server problem. Thanks. – user7358369 Dec 27 '17 at 05:35
  • I was going to post a quick test here but it is too large. I will post an answer and update based on your results. – Yepher Dec 27 '17 at 16:25

1 Answers1

0

I suppose an API key can cause that error but I generally only see that with a blank email from address. Did you give proper permissions to API the API key you are using?

Does this curl command work for you if you put in a good reply address, from address and your API key?

curl -X POST \
  https://api.sparkpost.com/api/v1/transmissions \
  -H 'Authorization: $YOUR_API_KEY' \
  -H 'Cache-Control: no-cache' \
  -d '{
   "options": {
    "open_tracking": true,
    "click_tracking": true,
    "transactional": true,
    "sandbox": false,
  },
  "campaign_id": "test",
  "recipients": [
    {
      "address": {
        "email": "test@example.com",
        "name": "test recipient"
      }, 
        "tags": []
    }
  ],
  "content": {
    "from": {
      "email": "test@dskmail.com",
      "name": "SparkPost Team"
    },
    "subject": "My Sample Subject",
     "text": "Big after Christmas sale...",
    "html": "Big after Christmas sale..."

  }
}

'

If you use Slack you may be able to get quicker feedback here: http://slack.sparkpost.com/

Yepher
  • 1,465
  • 12
  • 25