I want to loop through a few emails so that every time a form is submitted to myform.php, a different user is emailed.
Please note I am not looking for any functions to send mail. It happens to be emails being used, but the point is I need to know how to loop through a variable from a list of options.
This question isn't actually about emailing, because the form already works and sends email using a variable named $mail_to. Instead, this question is about looping a PHP variable each time a form is submitted.
Whatever I can do to loop them, the rest of the form works when putting an email into $mail_to like
$mail_to = '[email protected]';
What I want to do is instead of putting one email into $mail_to, instead I want to loop through a few emails. For example,
Emails:
[email protected]
[email protected]
[email protected]
[email protected]
In PHP form:
$email_looped = [???];
$mail_to = $email_looped;
Above, [???] is simply me saying in human terms I don't know what to do here.
Effectively, it will work like this in real time:
1st Visitor submits form from website >>
$mail_to= '[email protected]';
2nd Visitor submits form from website >>
$mail_to= '[email protected]';
3rd Visitor submits form from website >>
$mail_to= '[email protected]';
4th Visitor submits form from website >>
$mail_to= '[email protected]';
5th Visitor submits form from website >>
$mail_to= '[email protected]';
etc
How can I make it so that every time the form is posted to myform.php (from mypage.html), it chooses the next email in the list and loops them?
[email protected], second time form is submitted, send to[email protected], ... 5th time form is submitted, send to[email protected]again and keep looping on each time form is submitted.