Combining two arrays into a single variable

I am creating a form for our salesmen. In the form the salesmen can select one or multiple Customer Service Representatives (CSR) to have the form data emailed to.

Here is my form checkbox code for the Customer Service Representative selection:

[code]


Brian Corse
    Jake Egner
    Tom Miskovic
    Paulette Willits [/code]

I want to have the selected CRS’s linked somehow with their emails and then have the emails be somehow combined into the variable “$receiver” in the code below so that each selected CSR gets the form results.

[php]
if( mail( $receiver, $subject, $email_body, “From: $sender\r\n” .
“Reply-To: $sender \r\n” . “X-Mailer: PHP/” . phpversion()) )
{
echo “Success! Your job entry has been sent. Thank You.”;
}
[/php]

I’m just don’t know how to write the code that will loop through the CSR[] results, tie it to the CSR’s emails and combine it into the one variable. I’m assuming I will need to create an array from the values checked in the Cutomer Service selection, starting with $csrs = $_POST[‘csr’]; and have another array for the emails and I would guess use a foreach statement, but I don’t know how to connect the two and combine them into one variable.

I need help.

Adriana

If the $_POST[‘csr’] is an array, you could use implode:

[php]$receiver = implode(’, ', $_POST[‘csr’]);[/php]

To produce a string similar to:

[php]emailone, emailtwo, emailthree[/php]

I didn’t think of that. So if i understand correctly, I can make the checkbox input value the CSR’s email address and then the posted array could be imploded to create a string with the email addresses separated by a comma. I will try that. Thanks

Thank you so much jSherz, your solution appears to be working.

Sponsor our Newsletter | Privacy Policy | Terms of Service