Forwarding email to PHP Script?

Status
Not open for further replies.

tenx23

New Member
Messages
25
Reaction score
0
Points
0
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...
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
252
Points
63
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:

tenx23

New Member
Messages
25
Reaction score
0
Points
0
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/parse-emails-in-php-with-email-piping-part-2
 

tenx23

New Member
Messages
25
Reaction score
0
Points
0
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...
 
Status
Not open for further replies.
Top