Forum Moderators: coopster

Message Too Old, No Replies

Choosing Email Recipients on a Form

         

cookie2

4:51 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



I'm in the process of altering a prewritten PHP script that handles data from a form and sends a copy to the hard-coded address stated in: $incoming_mailto = "me@xyz.com";

I know I need to make it into a multiple field for people to select who they are sending it to like:

<input type="checkbox" name="incoming_mailto[]" value="me@xyz.com">The Boss</input><br>
<input type="checkbox" name="incoming_mailto[]" value="me@myemail.com">The Accountant</input><br>
<input type="checkbox" name="incoming_mailto[]" value="user@thisplace.com">The Office Manager</input>

But I'm drawing a blank on how I set the form to handle the results so that each checkbox that is checked will be mailed a copy of the form. I can't seem to get past having only one email sent regardless of how many boxes are checked. I know it's PHP 101 stuff but I'm completely blank. Can you help or point me where I can find out?

mincklerstraat

6:19 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



// make array of all possible mails that could be used - a security check
$permittedmailsarray = array(
'me@example.com',
'bob@hotmail.com',
'joe@yahoo.com;);
if(is_array($_POST['incoming_mailto'])){
foreach($_POST['incoming_mailto'] as $v){
if(in_array($v, $permittedmailsarray)){
(do your mail stuff here, w/ $v as the recipint address)
}
}
}
for the mail stuff - see the php manual on the mail() function.

timster

6:37 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know it's more than you asked for, but if this is an publicly available site, you may want to protect your email addresses from harvesting by spammers by leaving the emails off the input form. Just tweak minckler's plan like so:

<input type="checkbox" name="incoming_mailto[]" value="me">The Boss</input><br>
<input type="checkbox" name="incoming_mailto[]" value="Bob_Brady">The Accountant</input><br>
<input type="checkbox" name="incoming_mailto[]" value="Joe_User">The Office Manager</input>

<?php
// make array of all possible mails that could be used - a security check
$permittedmailsarray = Array(
'me' => 'me@xyz.com',
'Bob_Brady' => 'bob@hotmail.com',
'Joe_User'=> 'user@thisplace.com'
);
if(is_array($_POST['incoming_mailto'])) {
foreach($_POST['incoming_mailto'] as $v){
(do your mail stuff here, w/ $permittedmailsarray[$v] as the recipint address)
}
}
?>

cookie2

8:39 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Thank you both. I guess I was having a senior moment. ;)

I had intended to keep the email addresses hidden by putting them on the processing script itself. I only put them in the example to illustrate what I was looking to do.

Isn't it funny how something so simple can be so hard to recall? My thanks again.