need help with code irregular working code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NotGiven

    need help with code irregular working code

    The code below is designed to loop through rows of a database query
    obtaining email addresses and send an email to each. It is modified form
    fomr some code I found on the net.

    With each while loop, it updates the SENT field of the processed row to mark
    it sent. I have a sleep function in there to slow the processing down to
    see if that alleviated the following problem - it did help.

    What is happening is the first 20 emails it sends correctly. Then it starts
    sending with no $subject or $message but the remove form list text is still
    in the email. When I did it for a client, some clients ending up geting 5
    blank emails and one good email. It was bizarre and not uniformly wrong.

    When I send it, I follow the progress in almost real time by monitoring the
    test email account. When it started sending blank emails, I stop the web
    form used for sending.

    After I stopped it, I have about 35 emails. The database has about 1000
    addresses. However, the database shows that ALL rows' sent field were
    updated.

    Any ideas of how to improve or rewrite this to work? Could it be that it is
    on a shared server and there's something going on there?

    Many thanks for your help!


    <?
    $subject = $_POST[subject];
    $message = $_POST[message];
    $sql2 = "select address from email_table";
    $res2 = mysql_query($sq l2) or die("Couldn't get addresses.");
    $headers = "From: \"".FROMNAME."\ " <".FROMEMAIL."> \r\n"; //from a config
    file
    $email['fromemail'] = "me@mydomain.co m";
    $headers .="Return-Path: <me@mydomain.co m>\r\n";
    while ($row = mysql_fetch_arr ay($res2)) {
    $email_addr = $row[0];
    if (INSERTLINK == "true") {
    $fullmessage = $message . "

    -------------------------------------------------------
    If you would like to remove yourself from this list and receive
    no more emails, please click on the link below to do so.

    " . BASEHREF . "unsubscribe.ph p?email=" . $email_addr . "
    -------------------------------------------------------";
    }
    else {
    $fullmessage = $message;
    }
    mail("$email_ad dr", "$subject", $fullmessage, $headers, "-f
    {$email[fromemail]}");
    $sql3 = "UPDATE mail SET sent = 'y' WHERE address = '".$row[0]."'";
    $res3 = mysql_query($sq l3) or die("Couldn't update SENT field.");
    sleep(4);
    }
    echo "email sent!";
    ?>


  • Geoff Berrow

    #2
    Re: need help with code irregular working code

    I noticed that Message-ID: <aU10c.6882$0l1 .3684@bignews3. bellsouth.net>
    from NotGiven contained the following:
    [color=blue]
    > mail("$email_ad dr", "$subject", $fullmessage, $headers, "-f
    >{$email[fromemail]}");
    > $sql3 = "UPDATE mail SET sent = 'y' WHERE address = '".$row[0]."'";
    > $res3 = mysql_query($sq l3) or die("Couldn't update SENT field.");[/color]

    You are updating the database, whether mail() is successful or not.
    Since mail() returns TRUE if the mail was successfully accepted for
    delivery, you might be better off trying
    if(mail("$email _addr", "$subject", $fullmessage, $headers, "-f
    {$email[fromemail]}")){
    //update database
    }

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • NotGiven

      #3
      Re: need help with code irregular working code

      That didn't work either - thanks though



      "Geoff Berrow" <blthecat@ckdog .co.uk> wrote in message
      news:7ib140t4qq c1bp7nibdc4hpg0 qn2ml09un@4ax.c om...[color=blue]
      > I noticed that Message-ID: <aU10c.6882$0l1 .3684@bignews3. bellsouth.net>
      > from NotGiven contained the following:
      >[color=green]
      > > mail("$email_ad dr", "$subject", $fullmessage, $headers, "-f
      > >{$email[fromemail]}");
      > > $sql3 = "UPDATE mail SET sent = 'y' WHERE address = '".$row[0]."'";
      > > $res3 = mysql_query($sq l3) or die("Couldn't update SENT field.");[/color]
      >
      > You are updating the database, whether mail() is successful or not.
      > Since mail() returns TRUE if the mail was successfully accepted for
      > delivery, you might be better off trying
      > if(mail("$email _addr", "$subject", $fullmessage, $headers, "-f
      > {$email[fromemail]}")){
      > //update database
      > }
      >
      > --
      > Geoff Berrow (put thecat out to email)
      > It's only Usenet, no one dies.
      > My opinions, not the committee's, mine.
      > Simple RFDs http://www.ckdog.co.uk/rfdmaker/[/color]


      Comment

      • Sandman

        #4
        Re: need help with code irregular working code

        In article <aU10c.6882$0l1 .3684@bignews3. bellsouth.net>,
        "NotGiven" <noname@nonegiv en.net> wrote:
        [color=blue]
        > The code below is designed to loop through rows of a database query
        > obtaining email addresses and send an email to each. It is modified form
        > fomr some code I found on the net.
        >
        > With each while loop, it updates the SENT field of the processed row to mark
        > it sent. I have a sleep function in there to slow the processing down to
        > see if that alleviated the following problem - it did help.
        >
        > What is happening is the first 20 emails it sends correctly. Then it starts
        > sending with no $subject or $message but the remove form list text is still
        > in the email. When I did it for a client, some clients ending up geting 5
        > blank emails and one good email. It was bizarre and not uniformly wrong.
        >
        > When I send it, I follow the progress in almost real time by monitoring the
        > test email account. When it started sending blank emails, I stop the web
        > form used for sending.
        >
        > After I stopped it, I have about 35 emails. The database has about 1000
        > addresses. However, the database shows that ALL rows' sent field were
        > updated.[/color]

        Did you check your sendmail log (provided you use linux)? It might give you
        some hints on what's happening.

        --
        Sandman[.net]

        Comment

        Working...