Help needed with Send Mail

I have a form that is partly populated from a query.

On Send, the data from the form is sent to Send Mail.

image

And the expression is $_POST.send_report_to.split(',') is used to form the repeat, ie in this case to send to three separate email addresses.

The problem is that it doesn’t work.

If I enter one email address on the form then it works. More that three then it fails with this error

message : "Invalid address: (to): neil@example.com,neil@example.tv,neilrigby@example.co.uk"

Here is the Send Mail

I can’t find any up-to-date tutorials for this which show an example like mine.

Also, I don’t know how “Output Filter” and “Output Fields” are used.

Can someone help please?

And here are the Steps

The To Email value in the send mail should just be $value

This will be each address as it repeats

@bpj Brilliant! Many thanks. I’ve been away from this for too long.

Can I ask a couple of other questions…

How can I make the name dynamic as well as the email address?
image

when I have something like this?
Neil Rigby <neil@example.tv>,John Simpson <john@example.com>,Paul Timmins <paul@example.co.uk>

The idea is that the form’s 'To' field is populated from a query but also allows the user to add an addisional email address manually like this…

Also, what are the “Output Filter” and “Output Fields” used for?

If you are referring to the repeat options, i think these are pretty much self explanatory …
When you enable the Output for the repeat, it will output the data you select to the front end.

So when Include is selected it will output only the columns selected in the output list:
Screenshot 2022-12-02 at 13.51.32

And when Exclude is selected it will output all the columns except the ones selected in the output list:
Screenshot 2022-12-02 at 13.51.59

As for your other question i don’t really understand your idea, so i can’t answer.

1 Like

I think Tagify could be your friend here. You could have it as an autocomplete to add existing addresses and allow custom ones too. Then you would repeat through the values.

If you wanted you could make the value/text for the tagify something like:

<input type="text" name="emailtags" dmx-bind:data="someserverconnect.data.myuseremaillist" tag-text="firstname+' '+surname+' <'+email+'>'"  tag-value="firstname+' '+surname+'%%'+email">

That way each tag will show like you have above. In the API file you can repeat through the values and use

$_POST.emailtags.split('%%')[0]

for the email address binding
and

$_POST.emailtags.split('%%')[1].default($_POST.emailtags.split('%%')[0])

for the name (use the default so custom added email addresses use the email as the ‘to name’)

Don’t forget to add a Tagify component through the UI. Copy/Paste the code will not add the necessary includes to your page unless you already have Tagify on that page

3 Likes

This is an excellent solution and well described.

2 Likes

@bpj Cheers Ben, great explanation. Never actually used Tagify so would never have thought of that option. Thanks.

1 Like