Hi All,

Firstly thanks James for the help with the REGEX - all woring in that regard 
now.

On my server PHP version 4.x.x runs by default so I use the following in a 
.htaccess file to force version 5.x.x

.htaccess
AddHandler application/x-httpd-php5 .php

I am running the following script and it runs fine in a browser - without 
errors and it is sending e-mail as expected and deleting files BUT I get the 
following error when I set it as a CRON.

/bin/sh: /home/tonya/public_html/cron/relay.php: Permission denied

The cron command is -

*/15 * * * * /home/domain/public_html/cron/relay.php

<?php

// mail relay - finds e-mail, processes it and send it on via e-mail

$to = "[EMAIL PROTECTED]";
$from = "[EMAIL PROTECTED]";

$directory = '/home/domain/mail/[EMAIL PROTECTED]/new/';

function get_subject($headers)
  {
  $headers = explode("\n", $headers);
  foreach($headers as $header)
    {
    if(strtolower(substr($header, 0, 8)) == 'subject:')
      {
      $subject= substr($header, 8);
      if(substr($subject, 0, 1) == ' ')
        {
        $subject = substr($subject, 1);
        }
      return $subject;
      }
    }
  }

$list = scandir($directory);

foreach($list as $filename)
  {
  if(substr($filename, 0, 1) == '.')
    {
    continue;
    }
  $text = file_get_contents($directory . $filename);
  $text = str_replace("\r\n", "\r", $text);
  $text = str_replace("\r", "\n", $text);
  $choppos = strpos($text, "\n\n");
  $headers = substr($text, 0, $choppos);
  $message = substr($text, $choppos + 2);

  $subject = get_subject($headers);
  $regex = '/[EMAIL PROTECTED]/';
  $message = preg_replace( $regex, '[e-mail prorected]', $message);

  mail($to, $subject, $message, 'From: '. $from);
//  echo("[" . $directory . "][" . $filename . "][" . $subject . "]\n");
  unlink($directory . $filename);
  }

?>
 

Reply via email to