1

I'm trying to leverage the Contact Form plugin so I can dynamically specify the To email/recipient (via a text input, not as a hidden field).

I've tried via my own plugin to tap into the beforeSend event and also via config (eg https://gist.github.com/cole007/e65f028cc58140ed3b0f6910fc9615d6).

However, the sent message always defaults to send to the recipient specified in the plugin settings. Any thoughts on how to resolve, or if this is indeed possible?

1

Reading the documentation it sounds like you should be able to specify toEmail using a text input. I'm guessing that it is using the default email because you aren't validating the email address first.

<input type="text" name="toEmail">

The plugin will get toEmail from the post request and validate it for use.

$toEmail = craft()->request->getPost('toEmail');
$toEmail = craft()->security->validateData($toEmail);
  • you'd think so but still defaulting/sending to the email address specified in the plugin settings :/ – Cole Henley Jun 13 '16 at 9:52
  • so should above be in my contactform.php config file or my plugin that is tapping into the beforeSend event? – Cole Henley Jun 13 '16 at 11:54
  • Cole, looking at the docs for the plugin, you don't need to use the onBeforeSend event for this, just add the toEmail text field to your form and then add the code above to your contactform.php config file and it should work. – Steve Rowling Jun 13 '16 at 12:14
  • @SteveRowling alas tried with several variations (including hashing the email in my config file before validating) but with no success – Cole Henley Jun 13 '16 at 12:31
  • Any way of debugging whether Contact Form is picking up my custom config? Shoving a plugin log into the Service and it is only picking up from the core plugin settings – Cole Henley Jun 13 '16 at 12:39

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.