How to pass dynamic data to email template desgined on sendgrid webapp ? :-| Sendgrid

后端 未结 2 1730
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 08:24

I integrated sendgrid email service with my sample application. & also able to send email to user.

But how to pass dynamic data to Email template design on se

2条回答
  •  一整个雨季
    2020-12-28 08:38

    I think it is possible now, by adding a substitutions key in the options. I also added the to key because that one is mandatory.

    $request_body = json_decode('{
      "personalizations": [
        {
          "substitutions": {
            "-first_name-": "John",
            "-last_name-": "Doe"
          },
          "to": [
            {
              "email": "john.doe@example.com",
              "name": "John Doe"
            }
          ]
        }
      }
    }');
    $response = $sg->client->mail()->send()->post($request_body);
    echo $response->statusCode();
    echo $response->body();
    print_r($response->headers());
    

    Template in Sendgrid looks like this:

    Dear -first_name- -last_name-,
    
    Foo bar...
    
    Kind Regards
    

提交回复
热议问题