Jump to content

Mail piping


Federico

Recommended Posts

Hello.

I've recently installed a PHP script, which works fine, to be executed when an e-mail comes.

Unfortunatelly when I send an e-mail to the address that was forwarded to the script, I get this error:

 

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  pipe to |/home/fpetit/Tpersonal.php
    generated by federico@fpetit.heliohost.org

The following text was generated during the delivery attempt:

------ pipe to |/home/fpetit/Tpersonal.php
       generated by federico@fpetit.heliohost.org ------

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-zts-20060613/ixed.5.2.lin' - /usr/local/lib/php/extensions/no-debug-zts-20060613/ixed.5.2.lin: undefined symbol: executor_globals in Unknown on line 0
Error in argument 1, char 3: option not found 
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
       php <file> [args...]
  -a               Run interactively
  -C               Do not chdir to the script's directory
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse <file>.  Implies `-q'
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -q               Quiet-mode.  Suppress HTTP Header output.
  -s               Display colour syntax highlighted source.
  -v               Version number
  -w               Display source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.

 

The script to be executed is:

 

#!/usr/bin/php -q
<?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(trim($lines[$i])=="") {
        // empty line, header section has ended
        $splittingheaders = false;
    }
    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";
    }
}
// $from1=strpos($from,'<')+1;
// $from2=strpos($from,'>',$from1);
// $from3=substr($from,$from1,$from2-$from1);
//Only for WLM
if (strpos(strtolower($from),'alert@mobile.live.com')!==false) {
    $message2=strpos($message,' ');
    $msncontact=substr($message,0,$message2);
    $cntpos=strpos($message,'):')+2;
        if (strpos(strtolower($msncontact),'[hotmail]')!==false) {
            $from='';
        } else {
            $message=$msncontact.substr($message,$cntpos);
            $from='WLM Alert';
        }
}
//Only for Y! Alert
if (strpos(strtolower($from),'y-alerts@reply.yahoo.com')!==false) {
    $from='Y!Alert';
}
// Insertamos PHPMailer
$subject='Hola';
$message='Este es el mensaje. Debe llegar a tu cuenta de Yahoo!';
$to      = 'federicopetit@yahoo.com.ar';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@personal.com.ar' . "\r\n" .
    'Reply-To: webmaster@personal.com.ar' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
return;
?>

 

As you can see I also included the hashbag at the beginning of the code. The script has 755 permission to be executed.

 

 

Thanks for your help

 

 

Link to comment
Share on other sites

How much can you comment out before PHP throws the error? It seems the PHP is searching for an extension that we don't provide.

 

 

Well, the PHP is quite simple. It executes fine in your server. The problem comes when is executed by the piping method.

 

Link to comment
Share on other sites

I fear it might be. Try placing it back into the public_html directory and then pointing your pipe towards it there. If that doesn't work, place it in the public_html/cgi-bin directory and let me know if that works.

Link to comment
Share on other sites

I fear it might be. Try placing it back into the public_html directory and then pointing your pipe towards it there. If that doesn't work, place it in the public_html/cgi-bin directory and let me know if that works.

 

 

Well, I don't know what happened, but all of a sudden it started working!. It seems there was huge delay with your SMTP server.

 

I also noticed that I can use PHPMailer, which is good for my application.

 

Anyway, I still receiving the bouncing e-mails.

The files are in the HOME directory.

Link to comment
Share on other sites

The bouncing emails are automatically replied to the sender. I suggest you add a bogus reply-to header.

 

but all of a sudden it started working!
I recompiled Apache/PHP yesterday - that's probably what did it.
Link to comment
Share on other sites

The bouncing emails are automatically replied to the sender. I suggest you add a bogus reply-to header.

 

but all of a sudden it started working!
I recompiled Apache/PHP yesterday - that's probably what did it.

 

 

Well :rolleyes: Thanks!

 

I don't know what a bogus reply is.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...