Mailto link with prefilled subject and body

Hello everybody,

is there any way to use the button element and set link to “mailto:”

but also add a prefilled subject and body?

On my side it always puts the defined subject and body also in the mailaddress.

Thanks for your help.

Hey Louis!

To do this, create a button, and then add an attribute:

Name: onclick
Value: window.location.href='mailto:someone@example.com?subject=Hello%20There&body=This%20is%20a%20test%20message.'

I just tested it and it works :smiley: You can obviously replace the mailto, subject, and body. Please keep in mind you need to URL encode the subject and body. I would just write it and then send it to ChatGPT and ask it to URL encode the text.

Hope this helps!

I’m pretty sure this can just be added directly to the button URL rather than using js? Or is bricks doing some sort of URL sanitation that is breaking it? (I haven’t tested)

You’re right, you can also add it to the href attribute of the link like this:

mailto:someone@example.com?subject=Hello&body=This%20is%20a%20test%20message.

Either way works!

1 Like