Forums

Email multiple table records

vividal 11 Mar, 2019
I would like to have a form where I can enter a message into a textarea field and email a set of rows from a table. I have the form set, the email function works if I use a text field in the form to be the recipient. I have a read_data that pulls the records I want that contains the email addresses, but I can't figure out how to do the loop event or if I need a loop. OR should I be doing this in CC6 instead of CF6?
healyhatman 11 Mar, 2019
So you just want the emails out of the read data to be used as recipients, is that right? Then put this in the recipients.
{var:read_data#.[n].model.email}
Replace # with the number in the black label of your read data action, model with your read data model name, and email with your email field name.
vividal 11 Mar, 2019
Does the email command need to be in a loop event? I placed your syntax (adjusted for my read_data, model & field but it is still blank. The read_data is in the load section. do I need it in the submit section?
vividal 11 Mar, 2019
Ok getting closer. moved the read_data to the submit section and now the emails show up in the recipients array but now the result is could not sent.

[email15] => Array
(
[recipients] => Array
(
[0] => REMOVED
[1] => test2@vividal.com
[2] => test4@vividal.com
[3] => test6@vividal.com
[4] => test7@vividal.com
[5] => test2@vividal.com
)

[subject] => test 4
[body] => test 4
[from_name] => REMOVED
[from_email] => REMOVED
[reply_name] => REMOVED
[reply_email] => REMOVED
[result] => the Mail could not be sent.
[var] =>
)
healyhatman 11 Mar, 2019
I assume [0] isn't literally REMOVED, right?
vividal 11 Mar, 2019
no I removed the address b/c it isnt a "test" address the same for the from and reply info.
healyhatman 11 Mar, 2019
And the FROM_EMAIL, that's on your domain right?
vividal 11 Mar, 2019
it works just fine until I put in the var statement (ie use a static entry only in the recipients field or have a {data:send_to} field in the form and put that in the recipients field)
healyhatman 11 Mar, 2019
OK odd. Try {var.join[, ]:read_data#.[n].mdoel.email}
vividal 11 Mar, 2019
no go.
[email15] => Array
        (
            [recipients] => Array
                (
                    [0] => test2@vividal.com
                    test4@vividal.com
                    test6@vividal.com
                    test7@vividal.com
                    test2@vividal.com
                )

            [subject] => test 1
            [body] => test 1
            [from_name] => REMOVED
            [from_email] => REMOVED
            [reply_name] => REMOVED
            [reply_email] => REMOVED
            [result] => the Mail could not be sent.
            [var] => 
        )
vividal 11 Mar, 2019
ok so i removed the join and it appears to be an issue if there are more than 5 entries in the recipients array. Thoughts on what is causing that or how to fix it?
vividal 11 Mar, 2019
CHANGE THAT. The issue is if there is a duplicate email address. my example had test2 listed twice. If I change the test2 to something unique I can send the email even if there are 7 email addresses.
healyhatman 11 Mar, 2019
Right then well you need to use DISTINCT(model.email):model.email in your Fields to Retrieve for your email list. data read.
vividal 11 Mar, 2019
So I have added DISTINCT(Emails2.parents_email_1):Emails2.parents_email_1 to my read_data Fields to retrieve and now the entries in the array are blank??? [0] is the entry from the "send_to" field, not the read_data

my Recipients List is {data:send_to},{var:read_data21.[n].Emails2.parent_email_1}
[email15] => Array
        (
            [recipients] => Array
                (
                    [0] => test8@vividal.com
                    [1] => 
                    [2] => 
                    [3] => 
                    [4] => 
                    [5] => 
                )

            [subject] => test 1
            [body] => trest
            [from_name] => Robert Scott
            [from_email] => REMOVED
            [reply_name] => Robert Scott
            [reply_email] => REMOVED
            [result] => the Mail could not be sent.
            [var] => 
        )
vividal 11 Mar, 2019
The select statement doesnt look right

  [read_data21] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `Emails2`.`team_id` AS `Emails2.team_id` FROM `lov_team_emails1` AS `Emails2` WHERE `Emails2`.`team_id` = '7' LIMIT 10000;
                )

            [var] => Array
                (
                    [0] => Array
                        (
                            [Emails2] => Array
                                (
                                    [team_id] => 7
                                )

                        )
vividal 11 Mar, 2019
I have a typo in my DISTINCT statement....so hang on
vividal 11 Mar, 2019
well fixing the typo in the field name has made it worse. Now i am getting this error when I hit the send button on the form:

1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DISTINCT(`Emails2`.`parent_email_1`) AS `Emails2.parent_email_1` FROM `lov_team_' at line 1

Emails2 is the model from read_data21 and parent_email_1 is the field I want (if I add the "s" back to parent, I dont get the error but there is no field with that name)
healyhatman 11 Mar, 2019
Works for me. What have you got your return type set to? Screenshot your read data action ?
vividal 11 Mar, 2019
Not sure where the return type you are asking about would be located. I have not changed any of the defaults. read_data attached

​[file=11705]read-01.png[/file]
​[file=11706]read-02.png[/file]
vividal 11 Mar, 2019
OK FIGURED IT OUT!!!!

I moved my DISTINCT Field to retrieve above my team_id field and it worked.
Max_admin 11 Mar, 2019
I added a fix to the next update to make sure the recipients addresses are unique!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
healyhatman 11 Mar, 2019
Could you add checks to the mail_output or to G2\Mail ? I'm painfully aware that all Joomla does is return FALSE if there's a problem (which.... I mean... WHY!?), but perhaps a lot of CF user issues could be avoided if your mailer class did its own checks and threw its own errors instead of just showing "Mail could not be sent".
Max_admin 11 Mar, 2019
Checks for what exactly ? the recipients list will be cleaned from duplicates with the new change!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
healyhatman 11 Mar, 2019
1 Likes
Check that recipient list exists and contains valid addresses. That the attachments actually exist. That the from email is valid. All the checks that sendMail returns an unhelpful FALSE on.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger