You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When assigning empty mail settings, JSON serialization returns an empty array but the API expects an object (or null, also works).
// for purpose of illustration, user has set this to false.$spam_check = false;
$from = newEmail(null, "test@example.com");
$subject = "Hello World from the SendGrid PHP Library";
$to = newEmail(null, "test@example.com");
$content = newContent("text/plain", "some text here");
$mail = newMail($from, $subject, $to, $content);
$to = newEmail(null, "test2@example.com");
$mail->personalization[0]->addTo($to);
$mail_settings = new \SendGrid\MailSettings();
// not adding any settings because spam check is false.if ($spam_check) {
$spam_check = new \SendGrid\SpamCheck();
$spam_check->setEnable(true);
$spam_check->setThreshold(1);
$spam_check->setPostToUrl('https://spamcatcher.sendgrid.com');
$mail_settings->setSpamCheck($spam_check);
}
$mail->setMailSettings($mail_settings);
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
echo$response->statusCode();
echo$response->body();
echo$response->headers();
Seems to be resolved by altering MailSettings::jsonSerialize() on L:569
I would imagine it possible to instantiate new SendGrid\MailSettings(); and then optionally add settings as flags are required at run time or by users options for a possible spam check.
Additionally, if you set Sandbox Mode to false explicitly:
$mail = new \SendGrid\Mail();
$mail_settings = new \SendGrid\MailSettings();
$sandbox_mode = new \SendGrid\SandBoxMode();
$sandbox_mode->setEnable(false);
$mail_settings->setSandboxMode($sandbox_mode);
$mail->setMailSettings($mail_settings);
You get a very similar error: "message":"Invalid type. Expected: object, given: array.","field":"mail_settings.sandbox_mode"
Issue Summary
When assigning empty mail settings, JSON serialization returns an empty array but the API expects an object (or null, also works).
Seems to be resolved by altering
MailSettings::jsonSerialize()
on L:569Steps to Reproduce
I would imagine it possible to instantiate
new SendGrid\MailSettings();
and then optionally add settings as flags are required at run time or by users options for a possible spam check.Technical details:
The text was updated successfully, but these errors were encountered: