i am creating a newsletter script, originally i thought that mail() would do but testing it now with 4 emails in the db, it took some time (2sec) to load the compeletion page, so im wondering whether there is a better way to send mail out...

    The default operation of mail() is fairly slow, so that you can catch errors and such from the smtp server. What you wanna do is either edit php.ini to include a -q switch, or launch sendmail by hand with the -q switch set there.

      tekky made a post to ma other thread which was about my newsletter script. the way i have it is 1 email per row, and tekky thought this was slowing it down.. so heres the code i came up with to put all the emails in one row...:

      $exist = mysql_query("SELECT email FROM $tablename"); 
      $exist = mysql_fetch_array($exist); 
      $existingemail = $exist['email']; 
      $newemail = $existingemail.', '.$_POST['email']; 
      $update = mysql_query("UPDATE $tablename SET email='$newemail' ");
      

        While it will certainly help to run all your updates at once, the real issue is that sendmail tends to run in a semi-interactive mode. I.e. when it's invoked, it will send the email to the smtp server up the chain and wait for confirmation that it could / could not be sent. while it doesn't wait for the email to go all the way to its destination, it does wait for the server to check the mail records in DNS and determine if the mail is deliverable.

        when you add the -q switch, you basically tell sendmail to batch process mail every x number of seconds ('man sendmail' for more info) so it no longer waits for the smtp server to determine if the email address is valid etc...

        I had to write an opt-in mailing list handler thing for marketing, and could process 100,000 emails in about 30 minutes (this was several years ago.)

          ive been looking on things, i think my host either can't or won't change the settings in the php.ini file, but ive heard that they can be applied in the mail() part..

          i noticed on php.net that the mail function has the:
          string_additional_parameters... can i add the -q to that? 🙂

            Yeah, that should work. The extra parameters thing didn't exist back in the day when I was doing it by hand (i.e. sendmail -q ...) so it's nice to have it now.

            Hope that helps.

              so if i used the following, dya reckon it could work? 🙂

              $extra = "/usr/sbin/sendmail -q";
              mail($to, $subject, $message, $headers, '$extra');
              

              do i just put -q or somthing else? i couldnt find any documentation to explain the different extras

                change the extra line to look like this:

                $extra = " -q10m"; 
                

                and it should.

                Note that the number after q is used to set the amount of time for sendmail to wait before batching it's sendmail. anything will likely work, but 1 to 10 minutes seems to have worked well in the past for me.

                  Originally posted by Sxooter
                  I had to write an opt-in mailing list handler thing for marketing, and could process 100,000 emails in about 30 minutes (this was several years ago.)

                  Wow! And it actually worked OK? I've always heard that sort of volume was well beyond PHP's mail() and you'd need to do SMTP directly.

                  Did you worry about handling bounces?

                  BTW, there appears to be a pretty slick mailer module over at cpan. Mojo mail uses it.

                    heres the scenario:

                    1. user enters email

                    2. i need to check email to see if its already in the database but the new method has put all the emails into one row, how can i query to see if the email is in that row, (because the WHERE clause you need to state the whole information in the row your looking for?)
                      [/list=1]

                      i wonder if this will work:

                      	$checkthis = mysql_query("SELECT * FROM $tablename");
                      	$checkthis = mysql_fetch_array($checkthis);
                      	$checkthis = strpos($checkthis['email'], $_POST['email']);
                      	if ($checkthis === true) {
                      		$emailvalidate=1;
                      	} else {
                      		$emailvalidate=0;
                      	}
                      
                      

                      with that i think it should work okies

                        since the emails are all on one row, deleting an email is slightly more tricky then just deleting the row, so i made this code to get the emails in the database (which does include the , if there is one) and then it checks the string to see if the email that has been entered for removal is somewhere in the middle or at the end of the string by looking for the ' ,' that is added to the end of string before the email therefor the last email doesnt have the , and there is a comma inbetween the emails, when the check is done the email is replaced with nothing ie: "" and then it updates the db...
                        ok heres the code:

                        	$exist = mysql_query("SELECT email FROM $tablename");
                        	$exist = mysql_fetch_array($exist);  
                        $existingemail = $exist['email']; $checkio = strpos($existingemail,$_POST['email'].' ,'); if($checkio === false) { $newemail = str_replace($_POST['email'],"",$existingemail);} elseif ($checkio === true) { $newemail = str_replace($_POST['email'].' ,',"",$existingemail);} $update = mysql_query("UPDATE $tablename SET email='$newemail' ");

                        one thing ive just thought of now, is that if the email being entered is the first email, it adds a space and comma before it, which will make an error when the mail() runs.. .will fix up some code to get rid of that error

                          Opening a port to an SMTP server and sending mass mails that way is much faster... mail() opens a port and closes it on each call to the function, sloooowwww....

                            Actually, superwormy, the big issue is that sendmail (i.e. the mail() function) normally waits for the smtp server to respond after doing DNS lookups and all (i.e. checking deliverability).

                            if you add the -q switch, the mail() function is quite peppy, having personally setup a system that could handle sending 100,000 emails in <1 hour on an old AMD K6-2-300

                              $newemail = str_replace($_POST['email'].' ,',"",$existingemail);
                              

                              it gets a parse error but ive tried different stuff and i cannot seem to fix it 🙁
                              tried making a new var:

                              $postemail = $_POST['email'].', ';
                              

                              but that dont work, anyone got any ideas?

                                What kind of network connection did you have Sxooty?

                                  Originally posted by csn
                                  What kind of network connection did you have Sxooty?

                                  Huge, fat. OC192 or something like that. Only used a fraction of it, as each email was only ~1k of text, with most of the content on our web site and a quick speal leading you there.

                                  The SMTP server was a big ol Sun box, and of course, we sent them out at night to make sure we weren't dragging down any machines on the same piece of network fabric as ours.

                                  That was the first application I wrote using Postgresql for another department, was back when...

                                    Originally posted by helz

                                    $newemail = str_replace($_POST['email'].' ,',"",$existingemail);
                                    

                                    it gets a parse error but ive tried different stuff and i cannot seem to fix it 🙁
                                    tried making a new var:

                                    $postemail = $_POST['email'].', ';
                                    

                                    but that dont work, anyone got any ideas? [/B]

                                    Not sure what you're trying to do, but it's generally fine to just send one email at a time, honestly. If you set the -q switch it's pretty fast, and no one sees anyone else's email address.

                                      So do the emails sent mask all the emails sent to (with that -q thing)?? 🙂

                                      the code is for the unsubscribe part, it checks whether the email is somewhere in the list or at the end, if it is at the end it just deletes the email, but if its at the end it deletes the email with the comma preceding it, if it is in the middle or start, it deletes the email and the comma proceeding it.
                                      heres the full code:

                                      					$exist = mysql_query("SELECT email FROM $tablename");
                                      					$exist = mysql_fetch_array($exist);  
                                      $existingemail = $exist['email']; $checkio = strpos($existingemail,$_POST['email'].' ,'); if($checkio === false) { $newemail = str_replace(', '.$_POST['email'],"",$existingemail); } elseif ($checkio === true) { $newemail = str_replace($_POST['email'].' ,',"",$existingemail); } $update = mysql_query("UPDATE $tablename SET email='$newemail' ");

                                        nevermind, the parse error cos i fecked up an if statement further up 😛, sorry 🙂