The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Filter Script

Discussion in 'General Discussion' started by mazarin17, Jan 14, 2005.

  1. mazarin17

    mazarin17 Registered

    Joined:
    Jan 13, 2005
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Hi everyone,
    I'm trying to write a php based script that will create disposable email addresses on my server, and possibly those of my clients. I'm writing it to work with cpanel, but have ran into a pretty big snag.

    Basically, the program is near completion, except for the part that pipes the email through to be processed. For some reason, every time an email is piped through to the program the sender gets notified of a failed delivery. This happens even when the data from the email is processed and forwarded on.

    Does anyone have any ideas? I made a simple script to see if it would just take an email and write it to a file, no luck. As you can tell, email processing is a new area for me.

    This is a chunk of code I had written to take the email and store it in a file.

    Code:
    #!/usr/local/bin/php
    <?php
    
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd)) {
        $email .= fread($fd, 1024);
    }
    fclose($fd); 
    
    $filename = 'email.txt';
    $fp = fopen($filename, "a");
    $write = fputs($fp, $email);
    fclose($fp);
    
    ?>
    
    If anyone could help I'd greatly appreciate it.
     
  2. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    Check the permissions of the script to which mail is being piped. When I first tried a similar thing I too received delivery failures.

    Since I couldn't figure out why things weren't working, I tried to execute the PHP script from the command line and encountered a permissions error.

    Try setting the permissions on the script as 0777 as this should work, and then work you way down from there if you want the permissions to be something more secure.

    By the way, I too tried to get a PHP script to write the contents of a piped mail to a file in the same directory in which the script was running and couldn't get it to work. Delivery failure messages showed PHP errors that were generated when the script executed and the PHP errors related to not having the permissions to open or write to the file I wanted. This was with the permissions of the file and the directory it was in set as 0777.

    For test purposes, try piping to the following script:

    Code:
    #!/usr/local/bin/php
    <?php
    	// read from stdin
    	$fd = fopen("php://stdin", "r");
    	$email = "";
    	while (!feof($fd)) {
    	    $email .= fread($fd, 1024);
    	}
    	fclose($fd);
    
    	
    	mail("yourself@domain.com", "your fancy subject", $email);
    ?>
    Make sure you set the permissions on the script as 0777 before uploading. This and the above script worked for me.

    For me, mail piped to PHP scripts is discarded after the script finishes executing. In my case I needed to keep the mail and to do so I set up two filters in Cpanel - the first to pipe the mail to the script and the second to deliver it to the relevant mailbox.

    Let me know how you get along.
     
Loading...

Share This Page