1

I am (attempting) to and for the most part succeeding in sending an email from a plugin.

My plugin has a textarea in the settings that allows the user to customize the message. The message looks like this by default:

{{ forms.textareaField({
    label:        "Guest Email Message"|t,
    id:           'guestEmailMessage',
    name:         'guestEmailMessage',
    instructions: "The email message."|t,
    value:        (settings.emailMessage ? settings.emailMessage : "<p>Use the link below to complete your request.<p><a href="{siteUrl}"></a></p><p>Regards,<br>{siteName}</p>"|t({ siteName: craft.app.siteName })),
    errors:       settings.getErrors('emailMessage')
}) }}

I would like to create something like this:

"<p>Use the link below to complete your request.<p><a href="http://www.mysite.com/slug/ASDFQWER123"></a></p>"

My first problem is, I haven't figured out how to properly escape the anchor parameter. I've tried single quote and a backslash \ (that one).

My second problem is how to generate a random token. I'd like to generate a random string or something. I thought something like getUrlWithToken(), but I'm at the twig level and I'm not sure how that translates.

It would be cool if when I visit the link I am sending I have a way to validate that in my template. Maybe it's a case of if the CSRF token matches? I'm not sure where to start.

Thank you for any suggestions!

1

My first problem is, I haven't figured out how to properly escape the anchor parameter.

I'm guessing you mean the link is being escaped (since Twig will do that by default) and you don't want it to? If so, you can use the |raw filter (http://twig.sensiolabs.org/doc/filters/raw.html).

My second problem is how to generate a random token. I'd like to generate a random string or something.

If you don't care if it's a cryptographically secure string, you can just use StringHelper::randomString() or StringHelper::UUID(). If you want a cryptographically secure random string, then you can use craft()->security->generateRandomString().

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.