Mass Email???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Mass Email???

Post by Mr. Tech »

I have asked this question before but never got the answer I wanted...

I want to set up a script where I can send out a mass email to my 6000+ mailing list subscribers...

How would be the best way to do this without any time outs etc...

Thanks!
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

I would not recommend using the mail() function in PHP for anything over 100 mails, not even using it by breaking out your recipients in batches of 25, 50, 100 etc. and looping with the function.

The mail function in general is pretty weak - your best option would be to open a socket to SMTP and package up the mail in an env and send it at once by using 'RCPT TO:' in the SMTP connection.

Make your connection by using fsockopen() or popen().

Look through the user notes on fsockopen() and you will see a few examples of sending mail to SMTP using this...

Mark
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Is this the sort of thing:

Code: Select all

<?php
 function httpPost($host, $path, $referer, $data) {
     $fp = fsockopen($host, 80);
   fputs($fp, "POST ".$path." HTTP/1.0\r\n");
   fputs($fp, "Host: ".$host."\r\n");
   fputs($fh, "Referer: ".$referer."\r\n");
   fputs($fp, "Content-type: application/x-www-url-encoded\r\n");
   fputs($fp, "Content-length: ".strlen($data)."\r\n");
   fputs($fp, "\r\n");
   fputs($fp, $data."\r\n");
   fputs($fp, "\r\n");

   $tmp_headers = "";
     while ($str = trim(fgets($fp, 4096)))
       $tmp_headers .= $str."\n";

   $tmp_body = "";
   while (!feof($fp))
         $tmp_body .= fgets($fp, 4096);

   fclose($fp);
   return $tmp_body;
 } 
?>
What would I put in the host, $path, $referer and $data fields?
Post Reply