3

I am trying to send a mail using the SendGrid PHP API library. It worked when I tried it yesterday but today the reponse just has zero information:

SendGrid\Response Object
(
    [statusCode:protected] => 0
    [body:protected] => 
    [headers:protected] => Array
        (
            [0] => 
        )
)

The following object is being used in the \SendGrid\SendGrid()->send() method:

SendGrid\Mail\Mail Object
(
    [from:SendGrid\Mail\Mail:private] => SendGrid\Mail\From Object
        (
            [name:SendGrid\Mail\EmailAddress:private] => test1
            [email:SendGrid\Mail\EmailAddress:private] => test@example.com
            [substitutions:SendGrid\Mail\EmailAddress:private] => 
            [subject:SendGrid\Mail\EmailAddress:private] => 
        )

    [subject:SendGrid\Mail\Mail:private] => SendGrid\Mail\Subject Object
        (
            [subject:SendGrid\Mail\Subject:private] => this is a test
        )

    [contents:SendGrid\Mail\Mail:private] => Array
        (
            [0] => SendGrid\Mail\Content Object
                (
                    [type:SendGrid\Mail\Content:private] => text/html
                    [value:SendGrid\Mail\Content:private] =>
<h1>sending mails</h1>
                )

        )

    [attachments:SendGrid\Mail\Mail:private] => 
    [reply_to:SendGrid\Mail\Mail:private] => 
    [personalization:SendGrid\Mail\Mail:private] => Array
        (
            [0] => SendGrid\Mail\Personalization Object
                (
                    [tos:SendGrid\Mail\Personalization:private] => Array
                        (
                            [0] => SendGrid\Mail\To Object
                                (
                                    [name:SendGrid\Mail\EmailAddress:private] => mr test
                                    [email:SendGrid\Mail\EmailAddress:private] => testtest@example.com
                                    [substitutions:SendGrid\Mail\EmailAddress:private] => 
                                    [subject:SendGrid\Mail\EmailAddress:private] => 
                                )

                        )

                    [ccs:SendGrid\Mail\Personalization:private] => Array
                        (
                            [0] => SendGrid\Mail\Cc Object
                                (
                                    [name:SendGrid\Mail\EmailAddress:private] => 
                                    [email:SendGrid\Mail\EmailAddress:private] => testtest1@example.com
                                    [substitutions:SendGrid\Mail\EmailAddress:private] => 
                                    [subject:SendGrid\Mail\EmailAddress:private] => 
                                )

                        )

                    [bccs:SendGrid\Mail\Personalization:private] => 
                    [subject:SendGrid\Mail\Personalization:private] => 
                )
        )
)

Obviously I used correct addresses in the tos and ccs sections. Is something wrong with the sent object?

Sjaak Diemen
  • 61
  • 1
  • 5

1 Answers1

0

Apart from the code if there are any other problems in sending mail the send-grid library remains silent without throwing any exceptions and just returns the response 0. I would suggest you to visit this link

  1. In php-http-client\lib create a folder Exception.
  2. Copy lib/Exception/InvalidRequest.php into the folder.
  3. Modify lib/Client.php

These modifications are to throw appropriate exceptions which will help you to find what could be the problem in your case and be able to take it further.

YGR
  • 98
  • 6