Formit dynamic emailTo not working

I followed this part in the docs on Specifying Dynamic To Addresses from a select input, but it doesn’t seem to work. Formit comes back with an error, telling me to specify atleast one recipient, so my guess is the emailTo is not properly set.

[[!FormIt?
  &hooks=`spam,email`
  
  &emailSelectTo=`
    [[!migxLoopCollection? 
      &packageName=`team`
      &classname=`Team`
      &tpl=`teamEmailAddress` 
      &outputSeparator=`,`]]`

  &emailSelectToName=`
    [[!migxLoopCollection? 
      &packageName=`team` 
      &classname=`Team`
      &tpl=`teamEmailName` 
      &outputSeparator=`,`]]`

  &emailSelectField=`recipient`
  &emailTpl=`email`
  &emailFrom=`name@email.com`
]]


// Form
<select name="recipient" id="recipient" required>
  [[migxLoopCollection?
    &packageName=`team`
    &classname=`Team`
    &tpl=`teamEmailSelect`]]
</select>


// teamEmailSelect tpl
<option value="[[+id]]" [[!+fi.recipient:default=`1`:FormItIsSelected=`[[+id]]`]]>[[+name]]</option>


// teamEmailAddress tpl
[[+email]]


// teamEmailName tpl
[[+name]]

Is it a problem to fill those values with migxLoopCollection? Outside the Formit call, those work just fine.

From the example you linked

&emailSelectTo=`mail1@my.domain,mail2@my.domain;different@my.domain`
&emailSelectToName=`Mail1,Mail2;Different`

it seems the semicolon ; is used to separate the email-addresses and not the comma.


Also in teamEmailSelect you may need to use the index instead of the id for the value.

Didn’t realize that, working great now!
Why is there a comma after the first entries though? Is that a mistake or syntax for something additional?

In the example, if you choose the first option in the <select>, it sends the mail to 2 different email-addresses. These 2 email-addresses are separated by a comma.

(It’s basically the same as the &emailTo property, where you also can define a comma-separated list of email-addresses.)

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.