sendgrid-php icon indicating copy to clipboard operation
sendgrid-php copied to clipboard

setSubscriptionTracking 4th parameter $substitution_tag

Open milanIntermaps opened this issue 3 months ago • 0 comments

Can someone exmplain me how that substitution_tag works?

$email = new Mail();
        
        $email->setClickTracking(true, true);
        $email->setOpenTracking(true, "--sub--");
        $email->setSubscriptionTracking(
            true,
            "subscribe",
            "<bold>subscribe</bold>",
            "%%sub%%"
        );

        $email->setSubject("Sending with Twilio SendGrid is Fun 2");

        $email->addTo("[email protected]", "Example User");

        $email->setFrom("[email protected]", "Twilio SendGrid");

        $email->setGlobalSubject("Sending with Twilio SendGrid is Fun and Global 2");

        $email->addContent(
            "text/plain",
            "and easy to do anywhere %%sub%% , even with PHP"
        );
        $email->addContent(
            "text/html",
            "<strong>and easy to do anywhere %%sub%% , even with PHP</strong>"
        );

        $email->setAsm(629);
        $email->setFooter(true, "Footer %%sub%% YEY", "<strong>Footer %%sub%% YEY</strong>");

        $sendgrid = new \SendGrid('...');
        try {
            $response = $sendgrid->send($email);
            print $response->statusCode() . "\n";
            print_r($response->headers());
            print $response->body() . "\n";
        } catch (Exception $e) {
            echo 'Caught exception: '.  $e->getMessage(). "\n";
        }

I would expect that to do something with %%sub%% at any of the places, but nothing happend.

It gives me PLAIN like this

and easy to do anywhere %%sub%% , even with PHP
Unsubscribe From This List http://.../asm/unsubscribe/?user_id=...&data=... | Manage Email Preferences http://.../asm/?user_id=...&data=...
Footer %%sub%% YEY

It gives me HTML like this

<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
><strong>and easy to do anywhere %%sub%% , even with PHP</strong><a href=3D=
"http://.../asm/unsubscribe/?user_id=...&amp;data=...">Unsubscribe From This List</a> | <a href=3D"http://.../asm/?user_id=...&amp;data=...">Manage Email Preferences</a>
<strong>Footer %%sub%% YEY</strong><img src=3D"http://...=
/wf/open?upn=..." alt=3D=
"" width=3D"1" height=3D"1" border=3D"0" style=3D"height:1px !important;wid=
th:1px !important;border-width:0 !important;margin-top:0 !important;margin-=
bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padd=
ing-top:0 !important;padding-bottom:0 !important;padding-right:0 !important=
;padding-left:0 !important;">=

milanIntermaps avatar Oct 08 '25 17:10 milanIntermaps