Closed Thread
Results 1 to 4 of 4

Thread: Forwarding email to PHP Script?

  1. #1
    tenx23 is offline x10Hosting Member tenx23 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    25

    Forwarding email to PHP Script?

    I want to forward emails to a PHP script if thats possible...

    I want to emails sent to admins@-------.x10.mx to be readable with PHP script...

    I'm new also so you might have to explain stuff...

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Forwarding email to PHP Script?

    You will have to go to CPanel -> Mail -> Account level filtering -> Create new filter. Set the rule name to whatever you want, then filter based on "to" "equals" fill in admins@-------.x10.mx in the box. Set the action to "pipe to a program" fill in /home/tenx23/path/to/your/file.php, in example. You may want to add another action to "discard message" or else the message will also be delivered to the inbox. Finally, if your php file does not start with a hashbang, this is unlikely to work. The hashbang is #!/usr/bin/php -q. So, your file should look like this:

    Code:
    #!/usr/bin/php -q
    <?php
    // code starts here like normal
    ?>
    I haven't done this before, so you may need to do some google searching yourself to get all the answers.
    Last edited by garrettroyce; 03-27-2011 at 12:12 PM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    tenx23 is offline x10Hosting Member tenx23 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    25

    Re: Forwarding email to PHP Script?

    Thanks! Incase anyone is interested, you can read the email with this PHP code:

    Code:
     
    #!/usr/bin/php -q
    <?php
    // read from stdin
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd))
    {
    	$email .= fread($fd, 1024);
    }
    fclose($fd);
    ?>
    Note: After you got the email you have to parse through the headers and all that!

    This site helped me out: http://www.damnsemicolon.com/php/par...-piping-part-2

  4. #4
    tenx23 is offline x10Hosting Member tenx23 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    25

    Re: Forwarding email to PHP Script?

    Hmm I get the same Can't do setuid() (sperl) like I do with the autoresponder...

    It was escalated so hopefully when they fix that it'll apply to this aswell...

Closed Thread

Similar Threads

  1. Forwarding Email to PHP Script
    By brandon15811 in forum Programming Help
    Replies: 1
    Last Post: 11-14-2010, 08:00 PM
  2. Replies: 0
    Last Post: 08-12-2010, 11:10 AM
  3. Email Forwarding
    By mattpetriello56 in forum Free Hosting
    Replies: 1
    Last Post: 07-10-2010, 04:15 PM
  4. Email forwarding
    By daniel.faulknor in forum Free Hosting
    Replies: 5
    Last Post: 08-23-2005, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers