hm.. basically what I did to get it to work was put the path to the script in a .forward file, change the first line of the script to the path to PHP (finding the correct path using the shell command "which php"), and then chmodded the script to 755. One problem I had was that editing the first line of the script in Dreamweaver caused problems, so I had to do that part using PICO and then it worked. Also, my first host didn't allow piping, and it took me a long time to realize that was the problem. When I switched hosts it worked fine.
To test the script I used the shell command:
cat file-which-contains-a-valid-mail-address | /pathtomailscript/incomingmailscript.php
which lets you see whether it works without sending email and waiting.
here is my exact script if it helps (change the email address at the bottom, obviously -- I think this is verbatim from the article, aside from the top line). good luck and let me know if I can add anything.
#!/usr/local/bin/php
<?php
//The email is sent to the script through stdin. This is a special 'file' that can be reached by opening php://stdin. We will do that now and read the email.
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
//Now we have the full text of the email in the $email variable, we can start splitting headers from body. We will do that line by line, so the first step would be splitting the email. We also empty the variables that we will fill with the From header, the Subject header, and save other information in.
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
//We have just set the $splittingheaders variable to true. As long as this variable is true, and we have not yet seen an empty line, the text should be added to $headers. If we find a Subject or a From header, we will save it in the appropriate variable.
//After we have seen the first empty line, we have processed the headers and can start adding the lines to $message.
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;
}
}
$body = "Success.";
mail('myemail@gmail.com', 'Success', $body, 'From: noreply@nourl.com');
?>