Jump to content

MySQL/PHP Mailing List


MinusMyThoughts

Recommended Posts

i found it on here a few days ago, but now my search is coming up with different topics......i'm building my first newsletter system. i've gotten my code correct up to the point of being able to store user input in a database with two columns, the mailID (auto_increment) and the email......what i'm looking to do, hopefully, is run a while command to count up the mailID and send out an email to all the users on that list......my table is called "email" ......if someone knows the thread i found earlier, please link me to it. i'd love you forever if you could help me out......thanks!love,jason

Link to comment
Share on other sites

You need to use a query to get all the addresses:SELECT * FROM emailAnd then loop through it and send an email for each one. If you are sending bulk email, you might want to use the PEAR package. Unfortunately, the documentation for PEAR is so bad that I've never used it. Here is the API documentation for the mail package:

Mail 1.1.14Welcome to Mail!This documentation was generated by phpDocumentor v1.3.0
Sweet. That explains it all.You can either loop through and use PHP's mail function, which won't be very efficient, or you can send commands directly to sendmail if your server allows it, which will definately be more efficient, or you can use a class like this one:http://www.phpclasses.org/browse/package/3350.html
Link to comment
Share on other sites

alright, so let me try this. i don't have too many folks to write to, so i'll use a loop and the mail function for now...

$i = 0;while ($i < $mailID) {  mail($email, $subject, $body);  $i++; }

i've never written a while statement before, but i've read them on here. am i even close?love,jason

Link to comment
Share on other sites

wouldn't it be faster and more efficient to collect the email addresses into an array then send hte emial to all the addresses at once instead of using a loop of mail()?Or are you trying to make the meilas look more persoanlized in which case what you are doing would be best?

Link to comment
Share on other sites

Yeah, I was thinking that as well. But then everyone would have everyone else's email address. But there is the BCC header, I wonder if the mail had no "to" address, or maybe the address it was sent from in the "to", and then have everyone else's address in the BCC header. The mail client wouldn't show the other addresses, I wonder how well that would work though. It might be worth some testing.

Link to comment
Share on other sites

I guess with a small number of addresses there wouldn't be much benefit but I am guessing with a very large mailing list mailing to everyone at once would be far more efficient.I use the BCC for such situations so everyones email address is not exposed.

Link to comment
Share on other sites

what would "large" mean?...the site i'm developing for has only been around for a week and already has 100+ subscribers to the newsletter......how would i do an array mailer? even if i don't end up using it for this project, i'd love to learn how to do it for future reference...love,jason

Link to comment
Share on other sites

sorry. i was making up words......is there a tutorial on putting MySQL results into an array?...also, i set up the BCC the same way as TO, right?

$bcc = "BCC: ".myArray;

i'll have to look into arrays, as i've got zero experience with them. but thanks for the push in the right direction...love,jason

Link to comment
Share on other sites

That's basically how you use BCC, but you will need a comma-separated list of the address in it. Like this:BCC: address1@test.com, address2@test.cometcMySQL results are already in arrays, the mysql_fetch_assoc function gets a row from the record set as an associative array. Associative means you can refer to the fields by name instead of number. So you can use $row['id'] instead of $row[0]. If you want to compact all of the individual row arrays into one larger array, then you can do something like this:

$rowset = array();$result = mysql_query("SELECT * FROM email");while ($row = mysql_fetch_assoc($result)){  $rowset[] = $row;}

Now $rowset will be an array of all the other row arrays. So to access the email field of element 3 in the rowset, it would be like this:$rowset[3]['email']

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...