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

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    15

    I put together a script to send email to family members from a mySQL database. Newsletter type deal. I missplaced the loop and dumped a ton of emails in my test mailbox before I could shut it down. My backup email is the only one in the database for now, thank God!

    After the tongue lashing I got from my ISP and hosting company I am scared to death to try the following script (not to mention the hours I spent on the phone getting things straightened out). If I do it again I will loose both services. Please check this out for me.

    I have commented out the mail(... statement to test the loop (this won't send anything will it???). If I un comment it will it send only those in the database ok? Only once?

    $what2send is from an input box later in the program,
    receive is a field indicating they want the newsletter,
    email is a field containing their email address,
    fullname is a field containing their name.
    ********************************************************************

    $result = mysql_query("SELECT * FROM familydata WHERE (receive = 'Yes') ORDER by fullname ASC",$db);
    if ($myrow = mysql_fetch_array($result))
    do {
    // send email
    $email = $myrow["email"];
    /* ************
    * mail("$email", "Family Newsletter Test", "$what2send");
    ************ */
    printf("$email %s $what2send<br><br>n", $myrow["fullname"]);
    echo "Email sent ! <p>";

    } while ($myrow = mysql_fetch_array($result));

    ********************************************************************

    Please check this carefully. I can't begin to explain how this has messed me up!

    Thanks sooooooo much!

    stujo
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,647
    Rep Power
    4493
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by stujohnson:

    $what2send is from an input box later in the program,
    receive is a field indicating they want the newsletter,
    email is a field containing their email address,
    fullname is a field containing their name.
    ********************************************************************

    $result = mysql_query("SELECT * FROM familydata WHERE (receive = 'Yes') ORDER by fullname ASC",$db);
    if ($myrow = mysql_fetch_array($result))
    do {
    // send email
    $email = $myrow["email"];
    /* ************
    * mail("$email", "Family Newsletter Test", "$what2send");
    ************ */
    printf("$email %s $what2send<br><br>n", $myrow["fullname"]);
    echo "Email sent ! <p>";

    } while ($myrow = mysql_fetch_array($result));

    ********************************************************************
    [/quote]
    You forgot the brackets for your IF statement and you don't need the quotes around $email and $what2send in the mail statement.

    $result = mysql_query("SELECT * FROM familydata WHERE (receive = 'Yes') ORDER by fullname ASC",$db);
    if ($myrow = mysql_fetch_array($result))
    {
    do {
    // send email
    $email = $myrow["email"];
    mail($email, "Family Newsletter Test", $what2send);
    printf("$email %s $what2send<br><br>n", $myrow["fullname"]);
    echo "Email sent ! <p>";
    } while ($myrow = mysql_fetch_array($result));
    }


    If you are sending a lot of emails, your ISP might not like it. maybe you should clear it with them before hand?

    also, if you are sending a lot of emails, be aware of the exection time of your script. it will time out after 30 seconds (default). so if it takes to long to send out 1000 emails, then the script won't work.

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions... *
    * *
    * PHP Manual. www.php.net/manual *
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter *
    *************************************************************

    [This message has been edited by SepodatiCreations (edited October 05, 2000).]

Similar Threads

  1. send email through oracle
    By hurricane850 in forum Oracle Development
    Replies: 1
    Last Post: March 7th, 2005, 01:32 AM
  2. email form: send results to CSV attachment
    By dandcp in forum PHP Development
    Replies: 0
    Last Post: January 21st, 2004, 05:44 PM
  3. How to send an email directly into outbox using Netscape
    By kavita in forum HTML Programming
    Replies: 0
    Last Post: December 31st, 2003, 05:30 AM
  4. Using SMTP to send email - the only way?
    By vb.net in forum ASP Programming
    Replies: 1
    Last Post: December 1st, 2003, 11:38 AM
  5. How to send email in PHP if I do not have email server?
    By cooperchien in forum PHP Development
    Replies: 1
    Last Post: November 13th, 2003, 02:37 PM

IMN logo majestic logo threadwatch logo seochat tools logo