SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict richard_h's Avatar
    Join Date
    May 2002
    Location
    London
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mass mailing comments

    Just wondered if anyone has had any experience writting/ using a PHP script that handles large (5,000 +) mailing lists. This is what I've written so far for the sending -
    PHP Code:
    $mail = new phpmailer();
    $mail -> IsSMTP(); 
    $mail -> Host "mailserver.domain.com";
    $mail -> From "from@email.com";
    $mail -> Subject "free spam";

    $db = new MyDatabase($dbEzine$dbServer); 
    $db -> connect($user$pass);

        
    $sql ="
        SELECT 
        EmailAddress, 
        SubscriberFormatPK 
        FROM 
        Email, 
        Subscribe
        WHERE 
        SubscriberNewsletterPK = "
    .$this -> input['topic']."
        AND 
        SubscriberLanguagePK = "
    .$this -> input['lang']."
                        "
    ;
        
    $result $db -> query($sql);
        
    $q     = new QueryIterator($result);

        
    set_time_limit(0);

        
    $counter 0;
        while(
    $records $q -> getCurrent())
        {
            
    $mail -> AddAddress($records['EmailAddress']);

            
    $mail -> Body "hi ! \n\n enjoy your free spam; sent daily.";
            
    $mail -> WordWrap 50;

            if(!
    $mail -> Send())
            {
                echo 
    'Message was not sent - '.$records['EmailAddress'].'<br>';
                echo 
    'Mailer Error: ' $mail -> ErrorInfo.'<br>';
            }
            else
            {
                echo 
    'Message sent - '.$records['EmailAddress'].'<br>';
            }

            
    $mail -> ClearAddresses();

            
    $counter ++;
            if ((
    $counter 50) == 0)
            {
                
    sleep(30);
            }
            
    $q -> next();
        } 
    I'm using the phpMailer class - http://phpmailer.sourceforge.net/ to connect directly to the SMTP server; so avoiding the slow mail() function, also sending the email's out in batches of 50 with intervals of 30 seconds to prevent tying the server up.

    Any additional comments/ tips would be most greatful.

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2003
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to connect directly to the SMTP server; so avoiding the slow mail() function
    If you are using you local MTA, I wonder if there really is such a big difference. Do you know if anybody has actually measured such things?

    If you are sending large numbers of emails, it is a lot easier on the server if you are using BCC to send a single email to x users at once.

    Also in terms of performance it is important how well the MTA is configured (e.g. http://www.sendmail.org/~ca/email/doc8.12/TUNING )

    Sorry, if I cannot be of more help. If you search for "mass mailing" in these forums you will find a couple interesting topics in this like: http://www.sitepointforums.com/showt...ight=mass+mail

  3. #3
    SitePoint Addict richard_h's Avatar
    Join Date
    May 2002
    Location
    London
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are using you local MTA, I wonder if there really is such a big difference. Do you know if anybody has actually measured such things?

    If you are sending large numbers of emails, it is a lot easier on the server if you are using BCC to send a single email to x users at once.
    First off thanks for your comments. I've done some bench marks and with my server environment connecting directly to the SMTP server is faster than the mail function (approx 2 seconds for every 20 emails). My understanding is that the mail function has to open a separate socket connection for very email opposed to using one with my current approach. I also found that PHP was faster than Perl with my tests but there is no timeout issues with Perl.

    I'm interested with your comments concerning BCC, I was under the impression that the server still had to send each email individually regardless of being sent via BCC, are there not limits to how many you can add?


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
  •