How can i send to a random email out of a list?

smdubs 11 Oct, 2007
I have a group of people who will be responding to contact information from the form. How can i make it so it sends the email either a random address or have it so each time a form is submitted it goes to a different person.

Thanks
GreyHead 11 Oct, 2007
Hi smdubs,

Try this in the 'Onsubmit - before email' code field
<?php 
$emails = array('user1@example.com', 'user1@example.com', . . .);
$email_count = array_count_values($emails);
if ( $rows[0]->$extraemail ) {
  $rows[0]->extraemail .= ", ".$emails[mt_rand(0, $email_count)];
} else {
  $rows[0]->extraemail = $emails[mt_rand(0,$email_count)];
}
?>
Not tested, but the code looks OK. I suggest that you put some dummy emails in the first line (without the . . .) and run it a few times with debug on to see if all is well.

Bob
This topic is locked and no more replies can be posted.