ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262
Rep:
Quote:
Originally posted by fouldsy You will then have all your e-mail address stored in an array $email. A simple loop can then be used again to e-mail out whatever you need.
Supposing (from the different pieces of code I can read) you are using php as your scripting language, and supposing you really want to put all these emails in a variable separated by commas, you don't even need a loop. Just use the implode() fuction (alias join()).
That would work, but I don't see why the e-mail address would be constructed into a string before e-mail out. You'd end up with a massive string. Depending on the exact number of addresses being used, it might hit the size limit for a string variable. Plus, what if you then wanted to filter them or sort them? An array is much easier to work with than a long string. Effectively, you'd be e-mailing to multiple people from the one mail, meaning everyone sees the other addresses. The alternative is to run through each address as separate mail. You still the send the same number of e-mails, but in a slightly cleaner way.
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262
Rep:
Quote:
Originally posted by fouldsy That would work, but I don't see why the e-mail address would be constructed into a string before e-mail out. You'd end up with a massive string.
This is why I took the precaution to state: supposing you really want to put all these emails in a variable separated by commas
maybe you are better off using a perl script for that job. if u have to send huge numbers of emails the php script may run out of time. There is a maximal execution time assigned in php.ini.
You better keep track of where you already sent a mail in the database in case the script does not run thru the whole array of addresses. If u use php this is very likely to happen. So run an "update"-statement while looping thru the array...
cheers, j.
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262
Rep:
Quote:
Originally posted by newuser455 If I need it in a string, I can use $email, if I need an array I can use $email_array. Works fine for me .
PHP Code:
// retreive all email addresses
while (($row = mysql_fetch_array($result)) !== false){
$emails_array[] = $row['email'];
}
// Then use a loop to send email ...
foreach ($emails_array as $email) {
doSomeStuffWith($email);
}
// Or join all emails in a string
mail(implode(',', $mail_array), 'A test message', 'The content of test message', 'From: [email]blabla@nowhere.com[/email]');
Doing it this way as several (non exhaustive list....) advantages over your original piece of code:
you don't make unnecessary string operations
you don't use memory for a second variable containing duplicate data that you might not use
you limit the chances to have an other piece of code modifying one variable and not the other
your keep the ability to sort or filter your array before you implode it
you keep your code more clean, readeable and understandable
etc.
But you can of course still use you're piece of code that "works"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.