• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

UNIX command questions for setting up mail forwarding to PHP script

bitt3n

Senior member
I am trying to configure sendmail to forward email to a PHP script. I don't know UNIX and am having trouble figuring out how to forward the mail using shell commands. I think this is just a bunch of basic questions, but I have had little luck getting help elsewhere on my specific questions and it's driving me nuts. You can see the instructions I am trying to follow here: http://www.devarticles.com/c/a/PHP/Incoming-Mail-and-PHP/1/

The instructions say I need to do 3 things:

1) forward email using either a ".forward" file or a modified "alias" file (the preferable method, if I have "root access")

I want to use the alias file, seeing as it's the preferred method. Supposedly the alias file should be found in my /etc directory, but using shell access to my site I see no such file in the /etc folder off the top directory. Am I looking in the wrong place? Do I have to create it? If I want to create/modify the alias file to forward mail sent to script@myurl.com to "|/our/script.php", what specific command do I use?

With regard to the .forward file, I've been wandering around among the directories trying to find my mail folder so I can put the .forward file in there, but I have no idea where it should go.

2) Now the instructions say "Since our script will function as a shell script, the first line should contain the path to the PHP CGI program. This is most likely located at /usr/bin/php of /usr/local/bin/php. This tells the operating system that this script must be parsed by PHP."

I'm sorry for asking such a stupid question, but what does the "of" in "/usr/bin/php of /usr/local/bin/php" mean? I see a file "php@" in the directory "/usr/local/bin/php" but I do not know what is meant by "/usr/bin/php of /usr/local/bin/php". Also, how do I tell that PHP is compiled as a CGI module?

3) Once I write and save the script, I must put it in the correct location, and make it executable with "chmod 755"

Googling chmod, my understanding is that to do this, I navigate to the directory my script is in, and type "chmod 755 script.php" Is that right?

Thanks for your help.
 
Originally posted by: bitt3n
I am trying to configure sendmail to forward email to a PHP script. I don't know UNIX and am having trouble figuring out how to forward the mail using shell commands. I think this is just a bunch of basic questions, but I have had little luck getting help elsewhere on my specific questions and it's driving me nuts. You can see the instructions I am trying to follow here: http://www.devarticles.com/c/a/PHP/Incoming-Mail-and-PHP/1/

The instructions say I need to do 3 things:

1) forward email using either a ".forward" file or a modified "alias" file (the preferable method, if I have "root access")

I want to use the alias file, seeing as it's the preferred method. Supposedly the alias file should be found in my /etc directory, but using shell access to my site I see no such file in the /etc folder off the top directory. Am I looking in the wrong place? Do I have to create it? If I want to create/modify the alias file to forward mail sent to script@myurl.com to "|/our/script.php", what specific command do I use?

Try: find /etc -name "aliases"

On my system it's /etc/mail/aliases. If you have a virtual address on a shared server, you may not have access to this...

With regard to the .forward file, I've been wandering around among the directories trying to find my mail folder so I can put the .forward file in there, but I have no idea where it should go.

It should go in your home directory. ~/.forward.

2) Now the instructions say "Since our script will function as a shell script, the first line should contain the path to the PHP CGI program. This is most likely located at /usr/bin/php of /usr/local/bin/php. This tells the operating system that this script must be parsed by PHP."

I'm sorry for asking such a stupid question, but what does the "of" in "/usr/bin/php of /usr/local/bin/php" mean?

It should probably read "or."

I see a file "php@" in the directory "/usr/local/bin/php" but I do not know what is meant by "/usr/bin/php of /usr/local/bin/php". Also, how do I tell that PHP is compiled as a CGI module?

It depends on how you compiled it. If you used binary packages check their documentation.

3) Once I write and save the script, I must put it in the correct location, and make it executable with "chmod 755"

Googling chmod, my understanding is that to do this, I navigate to the directory my script is in, and type "chmod 755 script.php" Is that right?

Thanks for your help.

Yes, that's correct. You may need to use chmod 755 ./script.php instead, depending on how your environment is setup (./ just tells your shell to look for script.php in the current working directory).
 
Originally posted by: n0cmonkey
Try: find /etc -name "aliases"

On my system it's /etc/mail/aliases. If you have a virtual address on a shared server, you may not have access to this...
yeah, turns out I don't have access to it, AND my hosting provider modwest.com doesn't allow me alter .forward files or pipe emails to scripts.🙁

Now I'm looking for a new host.. I found one that a lot of people recommend (cartikahosting.com) but they use an older version of MySQL than I am currently using, and I am worried that it will break my code. The guy there said they use the version of MySQL prior to the one that allows nested queries (v4.0.26).

If what cartikahosting says is correct, I have queries that won't run under their version of MySQL. Is there some easy way to confirm that the following query will not run under MySQL v4.0.26 without actually subscribing to their hosting, setting up the database and running the script?

Also I just talked to brinkster.com and they said that piping email to scripts is not possible because their web servers are separate from the mail servers. I am just getting started with piping so while I assume this is correct, it would be great to get independent confirmation because that guy did not appear to be particularly knowledgeable.

 
Back
Top