FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » Piping email with php scripts
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Piping email with php scripts [message #160309] Mon, 17 August 2009 20:37 Go to previous message
wittrs is currently offline  wittrs   United States
Messages: 134
Registered: August 2009
Karma:
Senior Member
Hi. I'm getting an error each time I run this script. The error is "permission denied" and "cannot write to pipe." Here it is exactly:

sh: /hsphere/local/home/ludwiggroup/FUDforum2/scripts/maillist.php: Permission denied
sh: /hsphere/local/home/ludwiggroup/FUDforum2/scripts/maillist.php: Permission denied
X-Powered-By: PHP/5.2.6
Content-type: text/html


Cannot write to pipe.


Here is the script. As you can see, there is a section that specifically says "cannot write to pipe." That is where it is getting caught. Do you see any issues here that might identify the problem? (Note that the script is accessing my email addy and is deleting the emails -- hence, it is working for that part]. Thanks for any help you can provide.



#!/hsphere/shared/php5/bin/php

<?php

define(SERVER_HOST, "mail.seanwilson.org");
define(SERVER_USER, "bogus2(at)seanwilson(dot)org");
define(SERVER_PW, "1234");
define(SCRIPT_LOCATION, "/hsphere/local/home/ludwiggroup/FUDforum2/scripts/maillist.php");

$mailing_lists = array(
1 => "bogus2(at)seanwilson(dot)org"
);


$mb = "{" . SERVER_HOST . ":110/pop3/notls}";
$mbox = imap_open ($mb, SERVER_USER, SERVER_PW) or exit("Invalid server ($mb), username, or password.\n");

if (FALSE != $mbox)
{
$c = 1;
$n = imap_num_msg($mbox);
$msgOutput = "";

while ($c > 0 && $c <= $n)
{
$msgHeader = imap_fetchheader($mbox, $c);
$msgOutput = $msgHeader . imap_body($mbox, $c);

$to = get_to_address($msgHeader);
$cc = get_cc_address($msgHeader);

$scriptNum = array_search($to,$mailing_lists);

if ($scriptNum === False)
{
$scriptNum = array_search($cc,$mailing_lists);
}

if ($scriptNum === False)
{
continue;
}

$scriptNum++;

if(!$PIPE = popen(SCRIPT_LOCATION . " " . $scriptNum, "w"))
{
print "Cannot open pipe.\n";
exit;
}

if (!fwrite($PIPE, $msgOutput))
{
print "Cannot write to pipe.\n";
exit;
}

pclose($PIPE);

imap_delete($mbox, $c);
$c++;
}
imap_expunge($mbox);
imap_close($mbox);
}

function get_to_address($message)
{
$message = str_replace("\r\n", "\n", $message);
$lines = explode("\n",trim($message));
foreach ($lines as $l)
{
if(strncasecmp($l,"To:",3) == 0)
{
$to_address = trim(substr($l,3));
break;
}
}
return($to_address);
}

function get_cc_address($message)
{
$message = str_replace("\r\n", "\n", $message);
$lines = explode("\n",trim($message));
foreach ($lines as $l)
{
if(strncasecmp($l,"Cc:",3) == 0)
{
$cc_address = trim(substr($l,3));
break;
}
}
return($cc_address);
}

?>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Launching a php script file
Next Topic: PHP FTP file upload
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Mar 29 08:48:58 GMT 2024

Total time taken to generate the page: 0.04125 seconds