Dinamic fields on emailTo with formit

Hi there, I have a dynamic form where people can submit up to 5 email addresses, I’m storing those addresses both as a placeholder and as a hook value, but the email plugin keeps throwing “An error occurred while trying to send the email. You must provide at least one recipient email address.”

But if I just add the addresses as text in the emailTo param, it sends the mails as expected

My formit declaration is as follows

 <p>mails! [[+bartendersEmails]] </p>
    &formName=`Single Bartenders`

The mails are listed correctly on the paragraph, yet the mail won’t be sent

The last lines of the enrollBartendersFiHook hook are:

$modx->log(modX::LOG_LEVEL_ERROR, "Lists are:\n $bartendersList \n$bartendersEmails ");

$hook->setValue(‘bartendersList’, $bartendersList);
$hook->setValue(‘bartendersEmails’, $bartendersEmails);

$modx->setPlaceholder(‘bartendersList’, $bartendersList);
$modx->setPlaceholder(‘bartendersEmails’, $bartendersEmails);

return true;

And in the MODx error log I’m getting the expected values.

Also checked this but not getting the mails sent,
and bascially added:

<textarea cols="50" rows="4" id="addressto_all" name="addressto_all" value="[[+bartendersEmails]]" class="hidden"></textarea>

and updated the email field to emailTo=`[[+addressTo_all]]

But I’m still getting the same error and no emails are sent, what could I be missing?


From this thread I added

$hook->formit->options['emailTo'] = $bartendersEmails;

and the new error is:

[FormIt] An error occurred while trying to send
                      the auto-responder email: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Check the big space, like something was missing, we are in modx 2.8.1

I think you have to use

$hook->formit->config['emailTo'] = $bartendersEmails;

in your hook to set the emailTo value. (Use config NOT options!)

In general: You can’t use placeholders in the properties of the call to FormIt, if these placeholders are set by the FormIt snippet itself. You try to use the value of a placeholder before it is set!

This error message

An error occurred while trying to send the auto-responder email: SMTP connect() failed.

is from the FormItAutoResponder hook. As this hook doesn’t use the emailTo value, I’m not sure how the error is connected to the changes you made in the hook.

1 Like

Thanks a lot, changing ‘options’ to ‘config’ did the trick!