www.webdeveloper.com
Results 1 to 4 of 4

Thread: phpmailer problem

  1. #1
    Join Date
    Mar 2006
    Posts
    413

    phpmailer problem

    Hi:
    I just started using phpmailer to send out emails using smtp. All was working fine until i was told to develop a system for sending out a batch of emails (currently upto 1000).

    problem is when i'm looping through (each email is personalised) it gets a couple and then slows right down, until its virtually at a standstill. i only get about 10-15 done before it seems to stop.

    here is what i have:

    PHP Code:
    //enquiries/bookings have been assigned whip out some emails
    $mail = new PHPMailer();    
    $mail->IsSMTP();   // send via SMTP
    $mail->Host "smtp.fasthosts.co.uk"// SMTP servers    
    $mail->Subject  =  "Thank you for your recent enquiry";
    $mail->IsHTML(false); 
                    
        
    //traverse enquiries
        
    while ($row $db->GetRow($db->result))
        {
            
    $enqID $row -> EnqID ;
            
    $contact $row -> Name ;
            
    $email $row -> Email ;
            
    $site $row -> Site ;
            
            echo 
    "<br>Name:" $users[$i][name] . " email: " $users[$i][email] . " tel: " $users[$i][tel];
            echo 
    "<br> Assigned: " $enqID " Contact: " $contact " Email: " $email " Site: " $site "<br>It was Assigned and Email Sent<br>";
            
            
    // query to asssign the enquiry to the selected user
            
    mysql_query("INSERT INTO Assignments (EnqID, Name) VALUES ($enqID$users[$i][name])") ;
            
    // query to update the unassigned status of the enquiry to assigned
            
    mysql_query(" UPDATE Enquiries SET State = 'Assigned' WHERE EnqID = " .  $enqID ) ;
            


            
    $mail->From     $users[$i][email];
            
    $mail->FromName $users[$i][name];
            
    $mail->AddAddress($email); 
            
    $message "      <p>Hi " $contact ": </p>
            <p>Thank you for your recent enquiry with " 
    $site ".</p>
            <p>Your enquiry has been passed onto " 
    $users[$i][name] . " who will be handling your query.</p>
            <p>We will try to reply to your query as soon as possible, however, if you require any further help in the meantime you can contact " 
    $users[$i][name] . " in the following ways:</p>
            <p>Email: " 
    .$users[$i][email] . "<br />
            Telephone: " 
    $users[$i][tel]. "</p>
            <p>Thank you<br />
            Regards</p>
            <p>THE " 
    strtoupper($site) . " TEAM</p> " ;
            
            
    $mail->Body     =  $message ;
            
    $mail->AltBody  =  $message ;
            
    $mail->Send() ;        
            
            } 
    can anyone help me out? Any help is appreciated

    Thanks guys
    Last edited by Sid3335; 06-02-2006 at 07:58 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,338
    Using PHP via a webserver to send mutliple emails is notoriously prone to timing out. For spammers, the typical solution is to send the message to multiple recipients at once, typically by using a long list of Bcc recipients. Obviously this is not possible since in your case each message is customized for each recipient. Also, you are doing two database queries per email, adding additional processing.

    Frankly, I suspect your best solution would be to look at developing a non-web-based script for this that can be run via the command line or perhaps as a cron job. However, this may eliminate PHP as an option if it's installed as a web module and not in CLI mode.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2006
    Posts
    11
    I would make sure you make a connection to the db inside your while loop. I've done this before and what happens is my connection is lost to my db since the connection was only for x seconds.

    This may help.

  4. #4
    Join Date
    Mar 2006
    Posts
    413
    isn't it pretty inneficient to connect for every message, considering i could have thousands eventually (probably not, but....).

    Isn't there any programs like phpmailer that can handle batch emailing?

    any other alternatives?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles