PHP/MySQL table question
I am trying to write a script that has a mass mail function, which sends an email to everyone in a database.
My MySQL table looks like this: id name email Anyways, all I want to do is output the email column to a string, such as PHP Code:
Does anyone know how I could do this, or a better way to set up the table? Thanks in advance. |
The easiest way is to run a loop whilst executing your query, and stick the e-mail addresses into an array. Something like:
Code:
$i=0; |
Quote:
Code:
$emailfield = implode(',', $email); |
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.
|
Quote:
|
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. |
Hmm.. well.. I came up with this code which actually works.
PHP Code:
|
Glad you got something going. Have fun!
|
Quote:
PHP Code:
|
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 :D.
|
Quote:
PHP Code:
|
All times are GMT -5. The time now is 02:24 PM. |