I have some forms that are used to send an email to moderate numbers of addresses at a time. Because of this, the processing of the form takes more time than I'd like it to. I've tried a couple of things, but neither are working.

failure #1: modifying my php.ini file to tell sendmail to not try to process the mail immediately, but to just put it into the queue:

php.ini
sendmail_path = "/usr/sbin/sendmail -t -q"

rather than the default:

php.ini
sendmail_path = "/usr/sbin/sendmail -t -i"

failure #2: specifying the additional parameter in the mail() function itself:

mail($to, $subject, $body, $headers, '-q');

Neither approach works. No error message -- but the mail never gets delivered, nor does it ever even get put into the mail queue. Anybody know why? Am I doing something wrong? Any better suggestions?

    If mail() succeeds, it means the message is in the queue. Messages always get queued in most MTAs, as far as I know - sendmail never delivers it immediately.

    However, in some circumstances it gets delivered very soon after, so it will be in the queue only for a very brief period.

    1. How are you determining that the messages don't get queued? Are you using the MTA logs?
    2. Does mail sent from the command line get delivered?
    3. Can you receive bounces, or access the mailbox which bounces get sent to in any way (Hint: if not, then that is a problem - fix it or get your sysadmin to do so)

    You should not need any special options to have the messages queued. They always are, by default.

    The normal way of determining why a message was not delivered is by reading the bounce message generated. Bounce messages are ALWAYS generated (although sometimes they go somewhere you don't expect or are themselves bounced).

    Mark

      Thanks for the reply, Mark.

      MarkR wrote:

      If mail() succeeds, it means the message is in the queue. Messages always get queued in most MTAs, as far as I know - sendmail never delivers it immediately.

      Yes, it does. The script won't go any further until the mail has either been delivered, or attempted to be delivered. Whatever can't be immediately delivered goes into the mail queue for later processing.

      MarkR wrote:

      However, in some circumstances it gets delivered very soon after, so it will be in the queue only for a very brief period.

      1. How are you determining that the messages don't get queued? Are you using the MTA logs?

      sendmail -bp at the command line to view the queue

      MarkR wrote:

      3. Can you receive bounces, or access the mailbox which bounces get sent to in any way (Hint: if not, then that is a problem - fix it or get your sysadmin to do so)

      Yes, I have access to the bounce mailbox. Nothing there. Unfortunately, i am the sysadmin.

      MarkR wrote:

      You should not need any special options to have the messages queued. They always are, by default.

      Whatever can't be immediately delivered is queued. I want to queue it immediately to let the script finish processing immediately.

        Hmm, I assume you are right. I don't normally use sendmail as a MTA. Our machines usually use exim or postfix, which behave as I described I believe.

        What does the sendmail doc say about this?

        It seems strange that the messages are neither being delivered, nor queued, nor are you getting an error back from mail() (Which should check the return value of sendmail, I assume).

        Is there any output on the web server's stderr?

        Can you reproduce this on the CLI?

        Mark

          Same issue when using the CLI. Here's the exact example:

          #!/usr/local/bin/php
          <?
          mail('kburger@discovercolorado.com', 'subject', 'body', "From: kburger@discovercolorado.com\r\nReply-To: kburger@discovercolorado.com", '-q');
          ?>
          # /usr/local/bin/php emailtest.php
          

          No output at the command line. No error message. No email delivered. No email queued.

          Sendmail documentation says that the -q flag will queue the message rather than attempt immediate delivery. I've done this for years using Perl. I'm trying to do the same thing for PHP.

          By the way, this works fine, but it takes a few seconds to execute:

          #!/usr/local/bin/php
          <?
          mail('kburger@discovercolorado.com', 'subject', 'body', "From: kburger@discovercolorado.com\r\nReply-To: kburger@discovercolorado.com");
          ?>
          

            These may sound like daft questions, but please humour me:

            1. Are you absolutely sure that the sendmail you're invoking is really sendmail not some other MTA, to which "-q" means "Do nothing very much" ?
            2. What does the above do with error_reporting(E_ALL) ?

            Cheers
            Mark

              No problem. I appreciate you taking the time to respond.

              Yes, I'm absolutely sure it's sendmail. Here's the relevant output from phpinfo():
              sendmail_path /usr/sbin/sendmail -t -i

              Changing my php.ini file the way I indicated in my first post does indeed show my changes when looking at the output of phpinfo().

              Turning error reporting all the way up shows no errors or warnings at all.

              I'm still stumped.

                When I said "Make sure it's really sendmail", I didn't mean that /usr/sbin/sendmail exists, but that it isn't some other MTA disguised as sendmail (Which they do for compatibility).

                For example, on my system, "sendmail" is provided by Postfix. Postfix's "sendmail" uses the -q option for something completely different, which does not deliver any mail.

                You can check this on your OS by finding which package /usr/sbin/sendmail belongs to - on my (Ubuntu / Debian) systems,

                dpkg --search /usr/sbin/sendmail 
                

                Has the desired effect.

                I could be barking up the wrong tree, however what I've described fits the symptoms.

                Mark

                  OK, I see what you're saying. But it is actually sendmail. Unfortunately it's not a Linux system. It's Solaris. And as I mentioned, I can pass that flag to sendmail using Perl with no problem. It behaves exactly as it should. But for whatever reason, not with PHP. I have no idea why. And I'm really surprised that it doesn't at least complain when I try to do that. I can only guess that PHP is not sending that -q flag to sendmail correctly (actually that would be me not sending that flag correctly) and sendmail isn't sending an error to PHP, or maybe it is and PHP isn't sending that error out to STDOUT. I don't know. Just a guess.

                  Has anybody ever seen this issue before? Or does anybody know of any easy way to send the mail messages directly to the queue using the mail() function? I suppose if I really had to (and I might), I could use the PEAR::Mail_Queue class. But I'd rather not have to deal with the overhead. What am I missing?

                    If you use popen("/usr/sbin/sendmail -q", "w") ... does it work as expected?

                    Assuming you can reproduce this fault on the CLI, I recommend some strace()ing of the application (Perhaps it's actually called "truss" on Solaris)

                    Mark

                      Thanks for the tip. That opened my eyes to the problem. I'm ashamed to say that the -q flag doesn't tell sendmail to queue the message now as I originally thought. It really means "process the mail queue". Oops. Sorry to waste your time.

                      I discovered that by trying popen at the CLI like you suggested. When executed as a normal user I got this message:

                      can not chdir(/var/spool/mqueue/): Permission denied
                      Program mode requires special privileges, e.g., root or TrustedUser.

                      That opened my eyes. As root it executes just fine -- but not for delivering a particular message. It processes whatever's in the mail queue, ignoring whatever I write to the handler I assign to popen(). I should have known that. Stupid me. But it still seems strange to me that no warnings or errors are thrown when I try to use the -q flag in the mail() function in a webpage. It just seems to ignore it and move on. Beats me.

                      I'm going to look into using the PEAR::Mail_Queue package. Thanks for all your help. I really appreciate it.

                        Write a Reply...