• Resolved iperez_genius

    (@iperez_genius)


    In the past I was instructed to add this code inorder to augment the email call for Sendgrid.

    add_filter( 'wp_mail_smtp_providers_mailer_get_body', function ( $body, $mailer ) {
    
     if ( $mailer === 'sendgrid' ) {
      $body['template_id'] = 'templateId';
     }
    
     return $body;
    }, 10, 2 );

    I am now in need to add another parameter and am unsure of how to do that. Here is php code from the sendgrid API reference.

    $tracking_settings = new TrackingSettings();
    $click_tracking = new ClickTracking();
    $click_tracking->setEnable(true);
    $click_tracking->setEnableText(false);
    $tracking_settings->setClickTracking($click_tracking);

    Any chance you can show me how to add these parameters to my call.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Victoria Sakal

    (@sakalvictoria)

    Hi, @iperez_genius!

    Thanks for getting in touch.

    You can’t use the code from the documentation, since we have self API integration and we don’t use SendGrid SDK.

    You can check all available options that you can add to the request body here.

    For example, if you want to enable click link tracking as you shared in the code snippet from documentation, you will need to add the next code after the $body['template_id'] = 'templateId'; line in the current code snippet:

    $body['tracking_settings']['click_tracking']['enable'] = true;
    $body['tracking_settings']['click_tracking']['enable_text'] = false;

    Here is a full code snippet that you should get:

    add_filter( ‘wp_mail_smtp_providers_mailer_get_body’, function ( $body, $mailer ) {
     if ( $mailer === 'sendgrid' ) {
      $body['template_id'] = 'templateId';
      $body['tracking_settings']['click_tracking']['enable'] = true;
      $body['tracking_settings']['click_tracking']['enable_text'] = false;
     }
     return $body;
    }, 10, 2 );

    Kind regards.

    Thread Starter iperez_genius

    (@iperez_genius)

    Thank you for the fast reply. I have tested this and it works. One more quick thing. I need to get the email address that is being sent to.

    would i get that with $body[“email”]?

    Plugin Support Victoria Sakal

    (@sakalvictoria)

    Hi, @iperez_genius!

    Thanks for following up.

    The email can have several “To” recipients and they are stored in the $body['personalizations'][0]['to'] array. Here is an example of how to get the first recipient’s email address: $body['personalizations'][0]['to'][0]['email'].

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Click tracking Switch’ is closed to new replies.