0

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

2
  • 1
    Sounds like a recipe for spam, especially if the form is not secured properly...that is if that isn't what the original intention was. Commented 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. Commented Dec 12, 2010 at 23:59

2 Answers 2

4

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, will give it a go today!
1

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
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.