Cloudflare mailchannels dynamic name
# workers-help
z
Does someone know how can i set the from field dynamically from the one i have in the form (id=name)? Or any way I can debug to see the actual payload, https://developers.cloudflare.com/pages/functions/api-reference/#onrequests I'm guessing it's either in the data or in the request, but I'd rather not trying blindly. Thanks
Copy code
js
import mailChannelsPlugin from "@cloudflare/pages-plugin-mailchannels";
export const onRequest: PagesFunction = (context) => {
    var data = context?.data; // <-- That's just a test

    return mailChannelsPlugin({
        personalizations: [
            {
                to: [{ name: "Giulio Zanchetta", email: "giulio.zanchetta@majestico.it" }],
                dkim_domain: "majestico.it",
                dkim_selector: "mailchannels",
                dkim_private_key: context.env.DKIM_PRIVATE_KEY,
            },
        ],
        from: {
            name: `${data?.name}`,  // <-- Here I want the actual name inserted in the form
            email: "no-reply@majestico.it",
        },
        respondWith: () =>
            new Response(null, {
                status: 302,
                headers: { Location: "/thank-you" },
            }),
    })(context);
};