Error: Call to a member function getStatusCode() on null in SendGrid\Client

Created on 2 June 2023, over 1 year ago
Updated 14 July 2023, over 1 year ago

Problem/Motivation

I get the following error message when trying to send a test email

Error: Call to a member function getStatusCode() on null in SendGrid\Client->postRequest() (line 196 of \vendor\fastglass\sendgrid\src\Client.php)

#0 \vendor\fastglass\sendgrid\src\Client.php(150): SendGrid\Client->postRequest('/v3/mail/send', Object(SendGrid\Mail\Mail))
#1 \public_html\modules\contrib\sendgrid_integration\src\Plugin\Mail\SendGridMail.php(604): SendGrid\Client->send(Object(SendGrid\Mail\Mail))
#2 \public_html\modules\contrib\sendgrid_integration\src\Plugin\Mail\SendGridMail.php(147): Drupal\sendgrid_integration\Plugin\Mail\SendGridMail->doMail(Array)
#3 \public_html\modules\contrib\mailsystem\src\Adapter.php(50): Drupal\sendgrid_integration\Plugin\Mail\SendGridMail->mail(Array)
#4 \public_html\core\lib\Drupal\Core\Mail\MailManager.php(307): Drupal\mailsystem\Adapter->mail(Array)
#5 \public_html\core\lib\Drupal\Core\Mail\MailManager.php(180): Drupal\Core\Mail\MailManager->doMail('sendgrid_integr...', 'sengrid_integra...', 'me@gma...', 'en', Array, ' Localhost <...', true)
#6 \public_html\core\lib\Drupal\Core\Render\Renderer.php(580): Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}()
#7 \public_html\core\lib\Drupal\Core\Mail\MailManager.php(181): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#8 \public_html\modules\contrib\mailsystem\src\MailsystemManager.php(70): Drupal\Core\Mail\MailManager->mail('sendgrid_integr...', 'sengrid_integra...', 'me@gma...', 'en', Array, ' Localhost <...', true)
#9 \public_html\modules\contrib\sendgrid_integration\src\Form\SendGridTestForm.php(168): Drupal\mailsystem\MailsystemManager->mail('sendgrid_integr...', 'sengrid_integra...', me@gma...', 'en', Array, ' Localhost <...')
#10 [internal function]: Drupal\sendgrid_integration\Form\SendGridTestForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#11 \public_html\core\lib\Drupal\Core\Form\FormSubmitter.php(114): call_user_func_array(Array, Array)
#12 \public_html\core\lib\Drupal\Core\Form\FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#13 \public_html\core\lib\Drupal\Core\Form\FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#14 \public_html\core\lib\Drupal\Core\Form\FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('sendgrid_integr...', Array, Object(Drupal\Core\Form\FormState))
#15 \public_html\core\lib\Drupal\Core\Controller\FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\sendgrid_integration\Form\SendGridTestForm), Object(Drupal\Core\Form\FormState))
#16 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#17 \public_html\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#18 \public_html\core\lib\Drupal\Core\Render\Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#19 \public_html\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#20 \public_html\core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#21 \vendor\symfony\http-kernel\HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#22 \vendor\symfony\http-kernel\HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#23 \public_html\core\lib\Drupal\Core\StackMiddleware\Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 \public_html\core\lib\Drupal\Core\StackMiddleware\KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 \public_html\core\modules\page_cache\src\StackMiddleware\PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 \public_html\core\modules\page_cache\src\StackMiddleware\PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 \public_html\core\lib\Drupal\Core\StackMiddleware\ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 \public_html\core\lib\Drupal\Core\StackMiddleware\NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 \vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 \public_html\core\lib\Drupal\Core\DrupalKernel.php(718): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 \public_html\index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#32 {main}

Steps to reproduce

Install module and go to send test email after you have entered your secret key.
The following error happens when you send the test email

My setup
WAMP Localhost setup (SSL not active on localhost)
Drupal Version 9.5.9
PHP Version 8.1.18

💬 Support request
Status

Active

Version

2.2

Component

Code

Created by

🇿🇦South Africa vlooi vlerke

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @vlooi vlerke
  • 🇺🇸United States paulmckibben Atlanta, GA

    I'm seeing this error as well, but only in my local (ddev) environment. Once I push to a Pantheon dev environment, it works fine. It would be helpful if this could work in a local environment for easier testing.

  • 🇺🇸United States paulmckibben Atlanta, GA

    In further digging, my particular problem may be with the Colima container that ddev uses. See https://github.com/ddev/ddev/issues/4413

    In general, my problem seems to be "api.sendgrid.com" can't be resolved by my local ddev container.

  • 🇺🇸United States paulmckibben Atlanta, GA

    Confirming that by following @rfay's advice in https://github.com/ddev/ddev/issues/4413, I was able to resolve this problem for myself.

    This applies to local environments on ddev/MacOS/Colima:
    Type: colima restart -e
    And then edit the configuration file to modify the dns to use 8.8.8.8 and 1.1.1.1:

    # Network configurations for the virtual machine.
    network:
      # Assign reachable IP address to the virtual machine.
      # NOTE: this is currently macOS only and ignored on Linux.
      # Default: false
      address: false
    
      # Custom DNS resolvers for the virtual machine.
      #
      # EXAMPLE
      # dns: [8.8.8.8, 1.1.1.1]
      #
      # Default: []
      dns:
        - 8.8.8.8
        - 1.1.1.1
    
  • 🇮🇹Italy Niubbo75

    I got the same error but in production site, Drupal 9.5.10 PHP 8.1.20, any help will be appreciated, thanks!

Production build 0.71.5 2024