Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Sep 2007
    Posts
    6

    Default forward All recieved mail to a PHP file

    Hello
    Please Help me , i want forward All recieved mail to a PHP file , because i want create a virtual email system where any user from my site create a Valid email adress example : any@mysite.com for this work i want redirect all recived mail to a php file where that php file inserted into myDB
    tnx

  2. #2
    Member
    Join Date
    Jan 2005
    Location
    /dev/null
    Posts
    770

    Default

    search the forums for information about piping e-mail to a script, once you have the syntax you need set the default address on the domain to the pipe

  3. #3
    Member
    Join Date
    Sep 2007
    Posts
    6

    Default

    Hello , very thank you , but a problem , when any mail recived for me , and redirect to php script All text are saved to php file and my php file does'nt execute , i am use the #!/usr/bin/php in first line in my php code but not solved problem , and entire text in recived mails saved into php file
    please help me
    tnx

  4. #4
    Member
    Join Date
    Sep 2007
    Posts
    6

    Default

    No body cant't help to me ? please tell me , my php script does'nt execute in piping mail , and entire text from piping mail are saved to my php script !!

  5. #5
    Member
    Join Date
    Aug 2002
    Posts
    1,118

    Default

    If you are using the shebang line then you need to make sure that the PHP script is executable.

    You also need to make sure that the PHP script is not outputting anything, even a blank line can cause problems.

    Just do a quick run through of the script and see if everything is in order. You need to access the script from a shell, ideally as whatever user the script is going to be running as. So you really need to SSH into the server as that user, you may need to enable shell for that user to do the test.

    Then run the script:

    /path/to/phpscript.php >output.txt

    The shell will just sit there there, its waiting for input (if the script is coded right -- if you get an error or if the script exits, then you have a problem).

    Copy and paste a complete e-mail message, depending on how you've got the script written, headers may be necessary.

    When you have pasted that into the shell as the script is waiting for input, hit Ctrl+D to close out the input. The script should process the input and perform whatever task is needed.

    If you get an error, then you have a problem.

    Review the output.txt file. Is it empty? Does it contain anything? If it has any carriage returns or anything like that, then you have a problem.

    Depending on if and where you have a problem determines your next course of action. Unfortunately, I doubt very much that anyone here would be able to help that much as any problems would be a result of a coding error somewhere in the script.

  6. #6
    Member
    Join Date
    Sep 2007
    Posts
    6

    Default

    hi , very thank you , my script is :
    Code:
    #!/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; 
    	       	               }
    } 
    	       	                //For Testing Purposes
    	       	                $outFile = fopen("emails.txt","a");
    	       	                fwrite($outFile,$from);
    	       	                fclose($outFile);
    	       	                mail("myemail@yahoo.com", $subject, $message); 
    	       	                ?>
    maybe problem in this my code? because now i have not access to SSH . maybe this probelm depend on modular or CGI install PHP ?
    meanwhile my folder and this php script are CHMOD 777
    tnx
    Last edited by nasser110; 09-15-2007 at 05:14 PM.

Similar Threads & Tags
Similar threads

  1. Mail Not Being Recieved
    By turtles in forum E-mail Discussions
    Replies: 12
    Last Post: 06-26-2009, 06:03 PM
  2. Mail Not Recieved.
    By xqdm in forum E-mail Discussions
    Replies: 2
    Last Post: 06-24-2007, 02:05 AM
  3. Mail not being sent or recieved
    By Mini in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 04-14-2006, 04:21 AM
  4. forward mail to file
    By TechGuy in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 12-16-2005, 02:04 PM
  5. No e-mail sent or recieved
    By dsampaio in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 07-28-2004, 10:42 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube