sendgrid / sendgrid-php

The Official Twilio SendGrid PHP API Library
https://sendgrid.com
MIT License
1.49k stars 624 forks source link

Unable to send the mails with mimetype text/x-amp-html. #1035

Closed nehatlgt closed 3 years ago

nehatlgt commented 3 years ago

@thinkingserious Hi there, I am trying to send the AMP dynamic emails with sendgrid library. But I am unable to send, getting error of Invalid AMP in inbox. I have validated my amp template also, and its correct. But not able to send via library.

Does Sendgrid-php library support amp mime type?

Kindly help me in this:

Here is my code: include 'sendgrid-php/vendor/autoload.php'; $subject = "Thinks you'd love sign-up today!"; $email = new \SendGrid\Mail\Mail(); $email->setFrom("", ""); $email->setSubject($subject); $sendgrid = new \SendGrid(); $email->addTo(''); $body = "hi"; $email->addContent("text/plain", $body); $email->addContent("text/html", $body) $body = '<!doctype html><html ⚡4email>Hello World in AMP!'; $email->addContent("text/x-amp-html", $body); try { $response = $sendgrid->send($email); $sent = true; print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; die; } catch (Exception $e) { $sent = false; echo 'Caught exception: ', $e->getMessage(), "\n"; } return $sent; ?>

shwetha-manvinkurke commented 3 years ago

Hi @nehatlgt, from the documentation it looks like you need to be specifying the amp-mime type before the html mime-type. Ordering seems important here

nehatlgt commented 3 years ago

Hi @nehatlgt, from the documentation it looks like you need to be specifying the amp-mime type before the html mime-type. Ordering seems important here

Hi @shwetha-manvinkurke , I have rechecked with the ordering like

  1. text/plain
  2. text/x-amp-html
  3. text/html Still I am getting the same error.
shwetha-manvinkurke commented 3 years ago

Could you show me what the caught exception looks like? You could also do a error_log($e) to capture more details.

shwetha-manvinkurke commented 3 years ago

@nehatlgt Closing this due to inactivity. Feel free to reopen if you still need help.