Sendgrid php: send email in text / plain and html

I am using the Sendgrid PHP API and would like to send emails in both text / plain and text / html,

I tried:

$request_body = json_decode('{
    "content": [
       {
          "type": "text/plain", 
          "value": "text version"
       },
       {
          "type": "text/html", 
          "value": "html version"
       }
     ], 
     "subject": "blabla €",
     ...
  }');

  $response = $sg->client->mail()->send()->post($request_body);

Result:

  • The error is not generated using Sendgrid.

  • subject becomes "blabla Γ’'Β¬" (if only text / html, subject received a fine of "blabla")

  • and I only receive an email with this type of content:

Content-Type: text / html; encoding = UTF-8

Expected Result:

I would like to send an email with just 2 types of content:

Content-Type: text / plain; encoding = UTF-8

and

Content-Type: text / html; encoding = UTF-8

Is it possible? Any ideas?

+4
source share

Source: https://habr.com/ru/post/1662844/


All Articles