How to solve “Invalid SMTPAPI Header” received from SendGrid

When you are sending an email via SendGrid SMTP service, you might face the error like mentioned above:

Invalid SMTPAPI Header
The unique_args variable must be a hash

This actually happen when the X-SMTPAPI header is malformed. eg.:

$args = [
    'unique_args' => [
        'foo', 'bar'
    ]
]

The sample above is invalid, as the unique_args must be an key/value paired type (associative) array

The correct sample would be:

$args = [
    'unique_args' => [
        'first-key' => 'foo',
        'second-key' => 'bar'
    ]
]

For more details check official documentation: https://docs.sendgrid.com/for-developers/sending-email/getting-started-smtp

Leave a Reply