#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    Montreal, Canada
    Posts
    72
    Rep Power
    14
    Simple question but I really don't know how to do this. I have seen PHP code handle more difficult email situations but nothing to address this.

    I have a database with email addresses, is there any already-made PHP script or even perl that takes each of these email addresses and sends out an email to each person.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    108
    Rep Power
    15
    (Freshly written: reply if does not work)

    ==============================
    $subject = "YOUR SUBJECT";
    $message = "YOUR MESSAGE";
    $email = "YOUR EMAIL ADDRESS";
    $user = "MYSQL USERNAME";
    $pass = "MYSQL PASSWORD";
    $database = "YOUR DATABASE NAME";

    $db = mysql_connect("localhost", $user, $pass);
    mysql_select_db($database,$db);
    $result = mysql_query("SELECT email FROM table", $db);
    $rows = mysql_num_rows($result);

    for($i=0; $i<$rows; $i++) {
    $myrow = mysql_fetch_row($result);
    mail($myrow[0], $subject, $message, "From: $emailn");
    }
    ==============================

    hope that helps!
    yoshi
    datera@datera.com http://www.datera.com <-- Tour the Web!
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,640
    Rep Power
    4476
    The only thing you have to worry about with this script is max execution time. It'll work fine for 100s or probably 1000s of emails, but at a point, it'll take to long to send all of the emails. If you don't think this will be an issue, then drive on. Otherwise, an option is to select 1000 emails, send those, refresh the page, select next 1000, send those, etc....Then it won't time out.

    My $0.02

    ---John Holmes...
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    Montreal, Canada
    Posts
    72
    Rep Power
    14
    Worked like a gem. How about making it a little bit more complicated. For example, supposing I want to get my message from a text file. Do I just read the file, store it into the string and thats okay. Will the formatting of the text be affected?

    $filename = "/tmp/graffiti.dat";
    // open the file
    $handle= fopen($filename,'a+');
    // write the string to the file handle
    fputs($handle, $graffiti);

    // close the file
    fclose($handle);

    $grafitti="$message";

    Will this be fine

    code lifted from devshed.com

Similar Threads

  1. Replies: 0
    Last Post: February 12th, 2004, 11:56 AM
  2. Replies: 0
    Last Post: February 2nd, 2004, 05:44 PM
  3. Replies: 1
    Last Post: January 15th, 2004, 05:16 AM
  4. sendmail to php using perl
    By jackfraser70 in forum Perl Programming
    Replies: 1
    Last Post: December 10th, 2003, 09:46 AM
  5. Replies: 0
    Last Post: November 28th, 2003, 08:16 AM

IMN logo majestic logo threadwatch logo seochat tools logo