send mass email in php

Discussion in 'PHP' started by ropo, Jul 13, 2010.

  1. #1
    what is the best way to send mass email in php. let say i want to send 1000 emails. should i send all emails at a time, or should i do looping? i read someone thread, he said that he got error "too much recipient" when sending mass email.. does looping consider as sending mass email?
    Thanks for helping..
     
    ropo, Jul 13, 2010 IP
  2. sickness01

    sickness01 Member

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    ya u dont want to do all at once, because then the other people will have all the emails, use while statement for it is my suggestion, while or a for statement
     
    sickness01, Jul 14, 2010 IP
  3. uzairjawed

    uzairjawed Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    create a cronjob service for an hour and run that code on it.
     
    uzairjawed, Jul 14, 2010 IP
  4. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just a tip. I created something similar to send a few hundred thousand e-mails a week.

    One way to get past spam filters (they were double opt-in emails, but our server was not white listed) is to use something like PHPMailer and connect to a google account.
    Then send the e-mails using their servers. Much better hit rate :).

    Combine this with google apps and you can send e-mails that originate from your domain name as well.
    
    <?php
    	require("class.phpmailer.php");
    	
    	$mailer = new PHPMailer();
    	$mailer->IsSMTP();
    	$mailer->Host = 'ssl://smtp.gmail.com:465';
    	$mailer->SMTPAuth = TRUE;
    	$mailer->Username = 'x@gmail.com';  // your gmail address
    	$mailer->Password = 'xxx';  // your gmail password
    	$mailer->From = 'x@gmail.com';  // your gmail address
    	$mailer->FromName = 'x'; // who it's from
    	$mailer->Body = 'This is the main body of the email';
    	$mailer->Subject = 'This is the subject of the email';
    	$mailer->AddAddress('dude@hmm.co.uk');  // who you're sending to
    	
    	if (!$mailer->Send()) {
    	   echo "Message was not sent<br/ >";
    	   echo "Mailer Error: " . $mailer->ErrorInfo;
    	} else {
    	   echo "Message has been sent";
    	}
    ?>
    
    PHP:
     
    Deacalion, Jul 14, 2010 IP
  5. dbsuk

    dbsuk Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    My personal solution for this would be a mysql database table that acts as a mail queue and a script that runs once per minute on a cron job, this script would retrieve a number of unsent (WHERE mail_queue.mail_sent = 0) rows from the "mail_queue" and join the "content" and "subject" fields from the "emails" table based on the "mail_queue.emails_id" and build and send the emails.
    As each email is sent I would update "mail_queue.mail_sent" to 1.

    (my personal favourite for sending email in PHP is Zend_Mail)

    DB tables example:
    mail_queue (fields: id, to_email, from_email, to_name, from_name, emails_id (related to emails table), mail_sent)
    emails (fields: id, content, subject )

    There would also need to be a script or admin system to get the emails into the "mail_queue" table and maybe a small CMS to manage the emails in the "emails" table, or you could just do this with Phpmyadmin.

    The cron script could also clean up the mail_queue table once a day or so.

    Just an idea ;-)
     
    Last edited: Jul 14, 2010
    dbsuk, Jul 14, 2010 IP
  6. ropo

    ropo Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i try do 1000 looping.. i got "Internal Server Error".. but in my inbox got 1000 mails..
     
    ropo, Jul 19, 2010 IP
  7. ropo

    ropo Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks all for helping..
     
    ropo, Jul 19, 2010 IP