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
Switch to threaded view of this topic Create a new topic Submit Reply
Piping email with php scripts [message #160309] Mon, 17 August 2009 20:37 Go to next message
wittrs is currently offline  wittrs   United States
Messages: 134
Registered: August 2009
Karma: 0
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);
}

?>
Re: Piping email with php scripts [message #160311 is a reply to message #160309] Mon, 17 August 2009 22:22 Go to previous messageGo to next message
wittrs is currently offline  wittrs   United States
Messages: 134
Registered: August 2009
Karma: 0
Senior Member
I fixed the error above. It was being caused by the the variable script number that was assigned from looking at my list array. Because I only had one thing in my array, the feature became useless. (It was increased to the value of "2" by increment, and I didn't have a 2).

But now, I'm getting another error. This one says:

Status: 500 Internal Server Error
X-Powered-By: PHP/5.2.6
Content-type: text/html

2 Simple questions:

1. When I fill in the script location of maillist.php in popfud (above), do I include its actual location or the character "1" that FUDforum appends when generating the executable line? Have you noticed that it adds a "1"?

2. Once I get this popfud to work without error, do I have to run the maillist.php file too? Or is the execution of one tantamount to the execution of the other, because of the pipe procedure?

Thanks and regards. (I think I'm getting close!)
Re: Piping email with php scripts [message #160312 is a reply to message #160309] Mon, 17 August 2009 22:49 Go to previous messageGo to next message
wittrs is currently offline  wittrs   United States
Messages: 134
Registered: August 2009
Karma: 0
Senior Member
I no longer have the internal server error. That was caused by syntax errors that were my own fault. But I have something interesting happening now. My version of popfud seems to be doing what it is supposed to. It goes into my email, and one at a time, it tries to write the email to maillist.php. It then deletes the mails.

But for some reason, it isn't allowed to write to maillist.php. Something won't let it. Here are the errors:

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

Is it because my FUDforum files are locked?
Re: Piping email with php scripts [message #160313 is a reply to message #160309] Mon, 17 August 2009 23:03 Go to previous messageGo to next message
wittrs is currently offline  wittrs   United States
Messages: 134
Registered: August 2009
Karma: 0
Senior Member
... ok, this error message has nothing to do with files being locked, or whether I specify the "1" at the end of the maillist.php.

No matter what, I get the same message:

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


The number of times that I get "permission denied" is equal to the number of mails. So it is going through each mail, one at a time, as it should. It is also deleting the mails, as it should. So popfud is working, I think, as it should.

Why isn't it allowed to pipe? The maillist.php file has the correct php binary at the top. What would cause this -- any ideas?

Sorry to have posted so much. Felt like I was close to getting it.
Re: Piping email with php scripts [message #160314 is a reply to message #160309] Mon, 17 August 2009 23:25 Go to previous messageGo to next message
wittrs is currently offline  wittrs   United States
Messages: 134
Registered: August 2009
Karma: 0
Senior Member
VICTORY

VICTORY

Laughing Shocked Very Happy

VICTORY!!!!

Apparently, there are permission settings on these files.

Houston, we have just sucessfully piped email to the forum.

And only one week of life was wasted.
Re: Piping email with php scripts [message #160324 is a reply to message #160314] Tue, 18 August 2009 15:33 Go to previous message
naudefj is currently offline  naudefj   South Africa
Messages: 3772
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Congratulations!

wittrs wrote on Tue, 18 August 2009 01:25
And only one week of life was wasted.


School fees are never wasted - we all need to pay them from time to time. If you need to do it again, I'm sure it will take you less than 15 minutes.
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Wed Dec 18 08:05:10 GMT 2024

Total time taken to generate the page: 0.02714 seconds