Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email piping with php script

Hi' I want to forward all the emails(which are come to my inbox) to php script and retrieve email content and save it in a file. So do that I was add email forwarder with piping path correctly.

Address to Forward :[email protected]

Pipe to a Program : /home/centuryw/public_html/stage/ana/osticket/upload/api/pipe.php

I have used following script as pipe.php

#!/usr/bin/php –q
<?
/* Read the message from STDIN */
$fd = fopen("php://stdin", "r");
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);
/* Saves the data into a file */
$fdw = fopen("mail.txt", "w+");
fwrite($fdw, $email);
fclose($fdw);
/* Script End */

But there was no output file and all email are bounced to my inbox again. Can anyone help me please?

like image 299
Chanaka Avatar asked Apr 08 '11 06:04

Chanaka


1 Answers

Make sure the PHP file has the execute bit set (i.e. chmod +x pipe.php).

like image 97
Tyler Menezes Avatar answered Sep 22 '22 02:09

Tyler Menezes