Forums

How can I send an email to different addresses? from FAQ not working

larry_g1s 06 Jul, 2018
I've followed the FAQ for sending to multiple emails based upon a dropdown element, but it's not working. It only sends it to the first email in the listing that has more than one. What could I be missing. I've attached an image of what I've do
GreyHead 08 Jul, 2018
Hi larry_g1s,

This looks as if you have copied and pasted chunks of the FAQ, I have no idea what code you are actually using. What do you see when you add a Debugger action?

Bob
larry_g1s 11 Jul, 2018
Well, I copied the code, but personalized it with my info. (i.e. emails, etc.) The only error I get is the one below.
The check marks I did on that image were just to show you what I was doing (i.e. CFV5, etc.)
larry_g1s 13 Jul, 2018
Just an update, I can get the first one working (i.e. send to single different user based upon a drop down). But changing the code to accommodate sending to multiple users associated with a selection doesn't work.
GreyHead 18 Jul, 2018
Hi larry_g1s,

That just shows that there are no reported errors. Please copy and paste the full debugger output.

Bob
larry_g1s 25 Jul, 2018
I apologize. Please see attachment. I don't see the 'Dynamic To' in the Array that is set up in the 'Advance Tab' of the email.
-- Larry
GreyHead 25 Jul, 2018
Hi Larry,

As you can see there is a , at the start of the To Email value so there is an 'empty' email address before that.

Again, Please copy and paste the full debugger output.

Bob
larry_g1s 25 Jul, 2018
I apologize, I thought that's what you needed. Here is all that is on the page:

Data Array
Array
(
    [option] => com_chronoforms5
    [chronoform] => Test02
    [event] => submit
    [first] => John
    [last] => Doe
    [email] => john.doe@supermail.com
    [recipients] => em2
    [reelSub] => 
    [message] => Testing email form.
    [Apply] => Apply
    [emails_to_use] => 
    [ip_address] => 00.71.0.66
)
Array
(
)

Errors
Array
(
)

Debug Info
Array
(
    [0] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:, larry@supermail.com
                    [2] => Subject:Test
                    [3] => From name:iA
                    [4] => From email:do-not-reply@supermail.com
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:John
                    [8] => Reply email:john.doe@supermail.com
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
<table>
<tr><td><strong>Applicants Name</strong></td></tr>
<tr><td>John Doe</td></tr>
<tr><td><strong>Applicants e-mail address</strong></td></tr>
<tr><td>john.doe@supermail.com</td></tr>
<tr><td><strong>Applicants Location</strong></td></tr>
<tr><td></td></tr>
<tr><td><strong>Applicants Message</strong></td></tr>
<tr><td>Testing email form.</td></tr>
<tr><td><strong>How Applicant heard about iA</strong></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><strong>Placement Level</strong></td></tr>
<tr><td></td></tr>
<tr><td><strong>Applicants Link Submission</strong></td></tr>
<tr><td><a href=></td></tr>
</table><br /><br />IP: 00.71.0.66
                )

        )

)
larry_g1s 25 Jul, 2018
P.s. this is what is in the custom code. I've changed the emails for this example:
<?php
// set a default recipient
$recipients = array( 'em1' );
if ( isset($form->data['recipients']) && $form->data['recipients'] ) {
$recipients = $form->data['recipients'];
}
$emails = array (
'em1' => array('test01@email.com'),
'em2' => array('test02@email.com', 'test03@email.com'),
'em3' => array('test02@email.com', 'test03@email.com')
);
$emails_to_use = array();
foreach ( $recipients as $v ) {
$emails_to_use = array_merge($emails[$v], $emails_to_use);
}
$emails_to_use = implode(',', $emails_to_use);
$form->data['emails_to_use'] = $emails_to_use;
?>
GreyHead 26 Jul, 2018
Hi Larry,

In the Debugger output 'emails_to_use' is empty.

And the recipients value is not an array which is what the Custom Code is expecting.

If you only have one value set for the recipient then you don't need this particular code.

Bob
larry_g1s 26 Jul, 2018
So if I have two emails I want to send to for an option (i.e. option em2 has two recipients) I wouldn't use this code?
larry_g1s 27 Jul, 2018
Sorry Bob, I'm confused...The user will only select one option from the dropdown. Depending on the option the form will need to go to more than one address. Which option on that FAQ would I go with?
GreyHead 29 Jul, 2018
Hi Larry,

All of the FAQ examples after the first one are for the case where the user can select more than one address - i.e. there is a multi-select dropdown or a checkbox group used for the selection.

If you don't need this but just want to send to more than one address then using an address list in the first case should work.
$emails = array (
'em1' => 'test01@email.com',
'em2' => 'test02@email.com,test03@email.com',
'em3' => 'test04@email.com'
);
Bob
dmachado 11 Oct, 2018
Hello,

Im trying to implement this code but just to confirm. the $emails = array its the the ID to get from the dropdown list


<?
// set a default recipient
$recipients = array ('11');
if ( isset ($form->data['recipients']) && $form->data['recipients']){
$recipients = $form->data['recipients'];
}
$emails = array (
'9' => array('xxx@ddd.com'),
'11' => array('axxx@ddd.com'),
'15' => array('cxxx@ddd.comg'),
'8' => array('cxxx@ddd.comg'),
'14' => array('fxxx@ddd.com'),
'7' => array('fxxx@ddd.com'),
'16' => array('fxxx@ddd.comg'),
'10' => array('xxx@ddd.com'),
'5' => array('portxxx@ddd.com'),
'12' => array('xxx@ddd.com'),
);
$emails_to_use = array ();
foreach ( $recipients as $v) {
$emails_to_use = array_merge ($emails[$v], $emails_to_use);
}
$emails_to_use = implode (',', $emails_to_use);
$from->data['emails_to_use'] = $emails_to_use;
?>

Do I need to implement anything else?


Thanks a lot!
This topic is locked and no more replies can be posted.