Hi guys,

I posted a question a while ago but I didn't get an answer...

I have tried to have email piped through to a script on my webhost, the script contains the following...


#!/usr/bin/php
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);

// handle email
$lines = explode("\n", $email);

// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;

for ($i=0; $i<count($lines); $i++) {
    if ($splittingheaders) {
        // this is a header
        $headers .= $lines[$i]."\n";

    // look out for special headers
    if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
        $subject = $matches[1];
    }
    if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
        $from = $matches[1];
    }
} else {
    // not a header, but message
    $message .= $lines[$i]."\n";
}

if (trim($lines[$i])=="") {
    // empty line, header section has ended
    $splittingheaders = false;
}
}

?>

However this script doesnt seem to accomplish what its supposed to...it gives a mail return, even though I set it so that it emailed me with what was sent through to it...

Can anyone tell me whats wrong with this?

Cheers

    "it gives a mail return" --- clarify (I'm stoopid, I guess)

    Only thing I see is that there might very well be a newline on the "blank" line and splittingheaders might never get sent to false. However, the problem you describe doesn't seem to fit that scenario.....

      Sorry my fault,

      What it does is give me a failed delivery, yet sometimes it does it's job, i.e; send an email to me with what was piped through to it...my host said it's something with the script, such as removing blank line between the path to php and the start of the script etc, I spent ages messing with it till I gave up lol.

      The main error I get is;

      pipe to |/home/mwood_2k/mail_shell.php
      generated by roleplay@barnsleyclub.co.uk
      Child process of virtual_address_pipe transport returned 1 from command:
      /home/mwood_2k/mail_shell.php


      Error in argument 1, char 3: option not found
      Failed loading /usr/local/Zend/lib/ZendOptimizer.so:
      /usr/local/Zend/lib/ZendOptimizer.so: cannot open shared object file: No such
      file or directory
      Error in argument 1, char 3: option not found

      And the mailing system is Exim, I don't know what is wrong with it, I'm not exactly n expert in php...all I wanna do is create a mailing group kinda thing, I can sort out the mysql stuff, just this stuff is rather new to me, the server stuff such as stdin etc, I need some help! lol

      Cheers

        Well, one thing I didn't say before was that your example script never actually calls mail() . So I added a $to="me@my.com" and this:

        $success=mail($to, $subject, $message, $headers);

        at the bottom, saved it as /home/me/pipemail.php and then called

        #cat somefile | /home/me/pipemail.php

        I got the mail rather quickly, as expected.

        I'm no PHP guru, but the ZendOptimizer error looks like a server/installation/configuration issue to me. You might look at http://www.zend.com/store/products/optimizer-troubleshooting.php

          I've been hunting around, and the common denominator seems to be permissions or something, whats this running from command shell or something? I DID have the mail() function on, I'm just trying to get it to stop sending me failed deliveries first 🙂

          As it's saying it cannot load shared object or file for zend? It's gotta be a permissions thing hasnt it?

          Oh and whats this code;

          #cat somefile | /home/me/pipemail.php
          

          Cheers

            Ok I have been doing some messing, when I run the file without a switch, i.e; -q, it returns with this error...

            "pipe to |/home/mwood_2k/mail_shell.php
            generated by roleplay@barnsleyclub.co.uk
            Child process of virtual_address_pipe transport returned 69 (could mean
            service or program unavailable) from command:
            /home/mwood_2k/mail_shell.php"

            Do you have any idea what that means? I have set permissions to executable, as usual etc, and only brings the zend error when I try and supress headers with the -q switch....

            I have included the mail function and I don't get any email back except the failed delivery....

            I'm puzzled...

              Originally posted by mwood_2k2
              As it's saying it cannot load shared object or file for zend? It's gotta be a permissions thing hasnt it?

              Maybe permissions, it also could be that the thing isn't installed properly...'no such file or directory' it said, right?

              Oh and whats this code;

              #cat somefile | /home/me/pipemail.php
              

              Cheers [/B]

              That is what I did to test your script...piped it a file. In this case it was a mbox from /var/mail/someuser....got some juicy news, too (jus' kidding!!) 😃

                Originally posted by mwood_2k2
                Ok I have been doing some messing, when I run the file without a switch, i.e; -q, it returns with this error...

                "pipe to |/home/mwood_2k/mail_shell.php
                generated by roleplay@barnsleyclub.co.uk
                Child process of virtual_address_pipe transport returned 69 (could mean
                service or program unavailable) from command:
                /home/mwood_2k/mail_shell.php"

                Do you have any idea what that means? I have set permissions to executable, as usual etc, and only brings the zend error when I try and supress headers with the -q switch....

                I have included the mail function and I don't get any email back except the failed delivery....

                I'm puzzled...

                Your script apparently is not running at a high enough privilege level for your MTA. See the Exim FAQ at http://www.moongroup.com/docs/exim/FAQ.html#SEC4

                  Actually it wasn't that, it was the fact that I wasnt uploading the file in ASCII, instead it was binary, so the file had lots of M's lol. It works now 🙂

                    Write a Reply...