I want to create a form, which is basically a text area which has e-mail addresses on new lines:
For example;
<textarea>
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected]
</textarea>
I then want this form to submit to a php page, which will split the e-mail addresses and put them into a loop, so I could paste a list of 300 e-mails into a text area, in that format, and then submit the form and it would do a foreach loop for EACH individual e-mail (e-mail them).
Could somebody please explain how I would split the e-mail addresses up individually and then process them into a loop?
Thanks a bunch
-
1Sounds like a recipe for spam, especially if the form is not secured properly...that is if that isn't what the original intention was.Jim– Jim2010年12月12日 22:41:09 +00:00Commented Dec 12, 2010 at 22:41
-
It is a form I will be using myself to send e-mails to a list of subscribers I have, save me putting them into a database and running it from there, make things easier and just paste them all into a text area and submit it. It won't be used by anyone else, just an administrative tool to make things easier.Latox– Latox2010年12月12日 23:59:42 +00:00Commented Dec 12, 2010 at 23:59
2 Answers 2
If the email addresses are comma separated, use
$addresses = explode(',', $textareaValue);
foreach ($addresses as $address) {
$address = trim($address); // Remove any extra whitespace
}
If you want to split the addresses on a number of different characters (comma, newline, space, etc) use preg_split in place of explode
$addresses = preg_split('/[\s,]+/', $textareaValue);
1 Comment
To get them into an array you can use PHP's explode function which splits a string up based on a string delimiter:
$email_addresses = explode(",\n", $email_address_string);
foreach ($email_addresses as $email_address) {
// Process $email_address
}