1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Mass mailing?

Discussion in 'PHP' started by giraph, Jul 17, 2006.

  1. #1
    I've heard the mail function doesn't do too well when used for mass mailing, does anyone have any experience with this? I will be sending out over 10,000 emails and I was just wondering if anyone could recommend a way to do it. Thanks
     
    giraph, Jul 17, 2006 IP
  2. dddougal

    dddougal Well-Known Member

    Messages:
    676
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    108
    #2
    I use the function to send out mass mails, iv never had any problems, i rip the email address's out of a mysql database. Something like this:

    while($row = mysql_fetch_array ($result))
    {
    echo "Mail sent to ";
    echo $row[0];
    echo "<br>";
    $to = $row[0];
    $subject = "My spam";
    $from_header = "From: ";
    mail($to, $subject, $body, $from_header);
    }

    Thanks
    Steve
     
    dddougal, Jul 17, 2006 IP
  3. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wouldn't the script timeout if I tried that with 10,000+ emails?
     
    giraph, Jul 17, 2006 IP
  4. Serpatinas

    Serpatinas Well-Known Member

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #4
    Split them 1-100, 101-200, 201-300 etc.

    or try a mail list manager : www.hotscripts.com/PHP/Scripts_and_Programs/Mailing_List_Managers/index.html
     
    Serpatinas, Jul 17, 2006 IP
  5. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Split them 130 times? I currently have over 13,000 emails.
     
    giraph, Jul 17, 2006 IP
  6. elklabone

    elklabone Peon

    Messages:
    242
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    We use PHPmailer and a script that uses pagination so it sends 100 emails at a time. (we send out 2,000 total emails at a time), so we have 20 pages to load. I've wondered if you could set up an auto-refresh to load the next page... a meta-refresh or something?
     
    elklabone, Jul 17, 2006 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Absolutely you can set up an auto-refresh for that.

    I wrote a PHP script that did just this once (the refresh thing, not the mass mailing thing). My script was actually for remotely copying a database from one server to another (even if one was MySQL, say, and the other was Postgres). I used the 'onload' trigger in my page to throw back to the script and start the next portion of code.

    I never released it because I wasn't sure if anyone else would be interested in it, but it's definitely doable, yes :)
     
    TwistMyArm, Jul 17, 2006 IP
  8. sandossu

    sandossu Guest

    Messages:
    2,274
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    0
    #8
    for mass email you should use SMTP
     
    sandossu, Jul 17, 2006 IP
  9. jolielove

    jolielove Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Right, you should use SMTP to send email (PHP support SMTP functions)
    Use REFRESH meta (HTML tags) to auto refresh your send-email page (send 100 emails each time) then you can leave it until all emails have been sent.
     
    jolielove, Jul 17, 2006 IP
  10. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks jolie, and welcome to the forum, I'll see if I can put something together tonight before I fall asleep.
     
    giraph, Jul 17, 2006 IP
  11. dddougal

    dddougal Well-Known Member

    Messages:
    676
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    108
    #11
    Hey mr giraph, let us know how ya get on, iv personally never had any problems sending mails upto a thousand at a time but i suppose it varies.
    The refresh thing is easy to do, its just like how bigdump works....Maybe download that and see how the code works.
     
    dddougal, Jul 18, 2006 IP
  12. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #12
    T0PS3O, Jul 18, 2006 IP
  13. sandossu

    sandossu Guest

    Messages:
    2,274
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    0
    #13
    i am sending them with mail() function using an idea from ipb and vbulletin. I am sending packages of 200.
     
    sandossu, Jul 18, 2006 IP
  14. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #14
    The orignal poster is correct, sending via mail() in a loop sucks.

    SMTP is a good idea. With a few PEAR::MAIL class libs, not all php servers have them by default, we created a mail loop that opens an SMTP socket for each 300 email batch and sends them. Using MIME we can format them properly with the correct headers and the mail usually gets through too. We also use SPF records for our sites and server.

    mail() opens and closes a socket for each and every email.

    vBulletin coders can take advantage of batch/SMTP mail with vbmail() using vbmail_start() and vbmail_stop();.
     
    noppid, Jul 18, 2006 IP
  15. wwm

    wwm Peon

    Messages:
    308
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #15
    did none here hear of cron?
     
    wwm, Jul 18, 2006 IP
  16. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Well I'm using swiftmailer which connects to my smtp server. I just sent 500 emails to myself. About 300 have come in so far, they're slowly coming in. But it seems like it worked. Actually there seems to be something wrong since the text in the messages isn't coming out right. Here's the code I used for sending the e-mails and reconnecting to the smtp server.
    
    	for($i = 0; $i < 500; $i++)
    	{
    		$swift->send(
    			'my-email',
    			'"Name" <my-email>',
    			'Message Subject'
    		);
    		if($i%100==0)
    		{
    			$swift->close();
    			$swift = new Swift(new Swift_SMTP_Connection('my SMTP server'));
    		}
    	}
    
    Code (markup):
    I'll update this thread when I get the message text to show up right.
     
    giraph, Jul 18, 2006 IP
  17. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #17
    Cron comes after you have an efficient program to run. The point here is creating a more efficient mail loop. Execution is secondary.

    For execution without cron and using pagination, look at the code in the vBulletin commbull hack. The code to do auto next page is in it.
     
    noppid, Jul 18, 2006 IP
  18. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Ugh, my Dreamhost server has been going up and down the last few days and it really isn't helping the testing of this.
     
    giraph, Jul 18, 2006 IP
    noppid likes this.
  19. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #19
    That is very frustrating. I know the experience. But you are kinda hitting it hard. :p

    I just downloaded swift to check it out. Lots of files to include. I have to read a bit more and see if I can make the footprint smaller. I'd like to use this over pear for an application to avoid those that use it needing host intrevention to get pear libs installed to PHP.

    But of course, I'll benchmarh swift against pear too. I mean if pear is as fast, three easy pear commands can get any server ready for pear. That would be nice if we could count on hosts. With swift, we have the footprint of the include files and updates to distribute. With pear, once installed, php updates will deal with pear lib updates automatically.

    Oh the pros and cons of a php mailer.
     
    noppid, Jul 18, 2006 IP
  20. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #20
    It seems when I close the connection and reopen it the message dissapears so it starts sending blank e-mails.

    
    
    			$swift->close();
    			$swift = new Swift(new Swift_SMTP_Connection('My SMTP server'));
    			$swift->addPart($plain_part);
    			$swift->addPart($html_part, 'text/html');
    
    Code (markup):
    Anyone with experience with swiftmailer that could help would be really appreciated.
     
    giraph, Jul 18, 2006 IP