SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Bad Loops!

  1. #1
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Bad Loops!

    I am writing a mailing list program and running into a bit of a problem, when I do this
    PHP Code:
    while ($row mysql_fetch_array($result)) {        
            
    $emil    '';
            
    $newMail $cookieMessage;
            
    $emil    $row[email];
            
    $newMail str_replace ('!email' "$emil"       $newMail);
            
    $newMail str_replace ('!fName' "$row[fName]$newMail);
            
    $newMail str_replace ('!lName' "$row[lName]$newMail);
            
    $newMail str_replace ('!city'  "$row[city]"  $newMail);
            
    $newMail str_replace ('!state' "$row[state]$newMail);
            
    $newMail str_replace ('!dts'   "$dts"        $newMail);
            if(
    $mailtail != ' '){
                
    $mailtail  str_replace ('!link',"http://www.freejokebooks.com/remove.php3?email=$emil&listName=$listName",$mailtail);
                
    $newMail  .= "\r\n\r\n" $mailtail;
            }
            
    mail($emil,$cookieSubject,$newMail,$emailHeader);
            
    $users2 .= '<br>User emailed: ' $emil;
        } 
    on a small list it works fine. The emails all go out and get the right items replace and it looks fine. HOWEVER, when done on a list larger than say 150, the emails in the "mailtail" start to get funky. I will get the email at the right address(es), but the unsubscribe link ( the one that replaces "!link" ) doesn't have the right email address (it should be the same as the account that received it, but it's not).

    Why is this happening and how do I fix it?
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't say for sure, but if you're positive 100 users or so will go through alright, why not break things up to send out x number of emails at a time, with a link or button to send out to the next x/100 or so? This is probably a good idea anyway, despite this problem.

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How odd.

    However, here are a couple of things worth trying:

    1) Grab all the data from the result set and bung it into a two dimensional array (that is an array with each element being a row from the result set). That way you have finished with the db connection before you go into the time consuming task of sending those emails.

    2) I place all my literal strings in double quotes when passing them to functions in PHP. I've experienced problems with passing them wrapped in single quotes. Maybe its just me Does anyone else have any similar experience?

    3) I recall reading at leaste one other similar thread here at some time. Maybe PHP is just not good at handling so many emails in the one go. Maybe PHP is running out of memory or there is some memory management issue in mail() that is manifesting itself (ie a bug in PHP).

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you ever considered playing around with creating your own mail() function? You can connect directly to sendmail and then send the email.

    PHP Code:
    function new_mail($from$to $subject$core_msg$header


    $cmd_line=sprintf("/usr/sbin/sendmail -r %s -t",$from); 
    $fp=popen($cmd_line,"w"); 
    $temp=sprintf("To: %s\n",$to); 
    $len=strlen($temp); 
    $ret_p=fputs($fp,$temp,$len); 
    $temp=sprintf("Subject: %s\n",$subject); 
    $len=strlen($temp); 
    $ret_p=fputs($fp,$temp,$len); 
    if (
    $header != ""

    $temp=sprintf("%s\n",$header); 
    $len=strlen($temp); 
    $ret_p=fputs($fp,$temp,$len); 

    $temp=sprintf("\n%s\n",$core_msg); 
    $len=strlen($temp); 
    $ret_p=fputs($fp,$temp,$len); 
    pclose($fp); 

    Why don't you try that? It will be a tad bit slower, but not near as finicky, as I've had problems with mail() in the past!

    If this doesn't help I would reccomend using a, "Send Next 100 Emails" link like TWT reccomends.

    God Bless, hope you fidugre it out,

    Alex Stanton
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Sendings

    Actually right now I do have the script breaking it up into 10 message sendings. So each time it only sends ten messages (ie, "order by id limit x, 10")


    So I wil try throwing everything into an array first, and then see if that helps at all. Perhaps it will.


    Also, the "make you own send mail" thing does work MUCH faster, but I found it to sto pworking after i started making the script more complex, so i deceided to not screw with that and just use the easy mail function.
    -Jeff Minard | jrm.cc - Battlefield 2 Stats


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •