I got it working, at first I would get the message bounced back with the following error:
----- The following addresses had permanent fatal errors -----|/home/script.php (reason: Service unavailable) (expanded from: <email@address.com>) ----- Transcript of session follows -----smrsh: "script.php" not available for sendmail programs (stat failed)554 5.0.0 Service unavailable
The solution was to create a symbolic link in /etc/smrsh to point to the script because smrsh only allows programs to be run from /etc/smrsh directory.
ln -s /home/script.php script.php
Below is the PHP code I used:
PHP Code:
#!/usr/bin/php
<?php
/*
symbolic link in /etc/smrsh for file
and a .forward file with the following info
"|/etc/smrsh/script.php"
[email]emailbox@address.com[/email]
*/
// 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;
}
}
// Cell Phone to notify
$to = "sendtoaddress@domain.com";
// Headers
//empty headers from above
$headers = "";
$headers = "From: [email]email@domain.com[/email] <email@domain.com>\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
Basically I will be using this script with Vonage, to notify my cell phone when I receive a new message, and also send the entire message to another box so that I can check it. But I'm sure it can have many more applications. I just threw this together as an example, I realize its not that clean and more can be done with it, but I figure someone will come across this thread in the future and wish there was some code. Hope it helps someone!
And it does run clean!!!
