Help Needed With A Php Piping Script (urgent)

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 23, 2009, 08:19 AM
431090 members and 298155 Topics
Latest Member: segzy brow
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Help Needed With A Php Piping Script (urgent)
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Help Needed With A Php Piping Script (urgent)  (Read 209 views)
internetpo (m)
Help Needed With A Php Piping Script (urgent)
« on: September 25, 2009, 05:58 PM »

Help! I have been working for a while with my programmer brother on a PHP piping script but have not yet succeeded yet. the script was supposed to pipe/ direct several e-mails from a certain address to a MYSQL database . But we dont seem to be getting the IMAP/ POP 3 settings correctly or maybe something else is wrong.

Need help to complete the project at hand, any ideas, pls anybody. I have a deadline. Sad
segsalerty (m)
Re: Help Needed With A Php Piping Script (urgent)
« #1 on: September 27, 2009, 05:22 PM »

can anyone understand what Poster really needs?
cant understand the problem

pipe/ direct several e-mails from a certain address to a MYSQL database
webdezzi (m)
Re: Help Needed With A Php Piping Script (urgent)
« #2 on: September 28, 2009, 03:48 PM »

have you tried reading the imap in your php manual, its easy
internetpo (m)
Re: Help Needed With A Php Piping Script (urgent)
« #3 on: September 29, 2009, 09:49 PM »

Quote from: webdezzi on September 28, 2009, 03:48 PM
have you tried reading the imap in your php manual, its easy
we have tried it but it didn't work.
Do I paste the piping script here.
webdezzi (m)
Re: Help Needed With A Php Piping Script (urgent)
« #4 on: September 30, 2009, 10:07 AM »

why not. i will suggest that the script checks your mail directory for new mails instead
which means d script must be run whenever u wanna  check for new mails.

same way outlook does.
yawa-ti-de (f)
Re: Help Needed With A Php Piping Script (urgent)
« #5 on: October 02, 2009, 07:18 PM »

Quote
have you tried reading the imap in your php manual, its easy

it is only easy for the person who knows.  If you doubt me, oya tell me how to go about manufacturing a rocket that can land you safely on mars?  Tongue
*dhtml
Re: Help Needed With A Php Piping Script (urgent)
« #6 on: October 04, 2009, 11:34 PM »

now where is the script? it appears the top-class webmasters are around but no script to debug!
internetpo (m)
Re: Help Needed With A Php Piping Script (urgent)
« #7 on: October 06, 2009, 07:40 AM »

Ok, here is the Ogbonge Script

#!/usr/local/bin/php -q
<?php
error_reporting(0);
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);

// handle email
$email=strip_tags ($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;
}
}

preg_match("/boundary=\".*?\"/i", $headers, $boundary);
$boundaryfulltext = $boundary[0];

if ($boundaryfulltext!="")
{
$find = array("/boundary=\"/i", "/\"/i");
$boundarytext = preg_replace($find, "", $boundaryfulltext);
$splitmessage = explode("--" . $boundarytext, $message);
$fullmessage = ltrim($splitmessage[1]);
preg_match('/\n\n(.*)/is', $fullmessage, $splitmore);

if (substr(ltrim($splitmore[0]), 0, 2)=="--")
{
$actualmessage = $splitmore[0];
}
else
{
$actualmessage = ltrim($splitmore[0]);
}
}
else
{
$actualmessage = ltrim($message);
}

$clean = array("/\n--.*/is", "/=3D\n.*/s");
$cleanmessage = trim(preg_replace($clean, "", $actualmessage));

// test action to be replaced by db insertion code
$body = "$cleanmessage";

//forward email
mail('myemailaddressgoeshere', $subject, $body, "From: ".$from);
 The forwarding works well, i get the mail forwarded to the email address.

//connect to sql
$db = mysql_connect ('localhost','don't worry','don't worry');

//select the database you created
mysql_select_db('don't worry', $db);
$query="INSERT INTO recievedMails(from,subject,headers,message) VALUES('".$from."','".$subject."','".$headers."','".$body."')";
$result = mysql_query($query);
?>


Expecting your help webmasters, thanks
internetpo (m)
Re: Help Needed With A Php Piping Script (urgent)
« #8 on: October 06, 2009, 07:51 AM »

by the way. WE have succeeded in Piping from one e-mail to another. but from one e-mail to a database has been hell, it seems not to be working. Embarrassed
yawa-ti-de (f)
Re: Help Needed With A Php Piping Script (urgent)
« #9 on: October 06, 2009, 09:35 AM »

1) This is how I write my sql insert statements:
$result = mysql_query("INSERT into tbl_subscription values (NULL, '$autoAssignedId', '$subscription', '$subscribedItem')");

NOTE the absence of "." around  '$autoAssignedId' (just in case you don't understand, see how you have the "From" written as '".$from.")

2) What has always worked for me and DBs is printing out the value of my statements.  Do an echo and exit after the statement to see if you actually have any values.

3) I don't see any checks after you insert like so:
if(!$result)
            return 'Could not pipe into the database at this time. ';

Try the above if not already and get back to us.  good luck!
webdezzi (m)
Re: Help Needed With A Php Piping Script (urgent)
« #10 on: October 07, 2009, 02:52 PM »

Quote from: yawa-ti-de on October 02, 2009, 07:18 PM
it is only easy for the person who knows.  If you doubt me, oya tell me how to go about manufacturing a rocket that can land you safely on mars?  Tongue

maybe if you import the rocket module for python
you should land safely,  Grin
yawa-ti-de (f)
Re: Help Needed With A Php Piping Script (urgent)
« #11 on: October 07, 2009, 03:23 PM »

internetpro (and to all others who may fall in the same category):
I forgot to mention this - Next time, please indent your code.  The way you have it up there (and I hope this isn't a reflection of your actual code Wink), it is very hard to read and follow the logic.

You want us to help you.  Help speed up the process by making it easier for us to read and follow your code

Thanks.
*dhtml
Re: Help Needed With A Php Piping Script (urgent)
« #12 on: October 07, 2009, 05:24 PM »

Now, that code appears to be in order, i did not check it thoroughly, now, how did you configure it on your control panel?
that may be where the issue is! i need to know how you implemented it.
internetpo (m)
Re: Help Needed With A Php Piping Script (urgent)
« #13 on: October 13, 2009, 10:29 AM »

@ *dhtml
I did not upload it to the public directory of my cpanel becos of security reasons. I uploaded it to the home directory and made the file permission executable.
fastchange
Re: Help Needed With A Php Piping Script (urgent)
« #14 on: October 13, 2009, 03:24 PM »

Quote from: yawa-ti-de on October 06, 2009, 09:35 AM
1) This is how I write my sql insert statements:
$result = mysql_query("INSERT into tbl_subscription values (NULL, '$autoAssignedId', '$subscription', '$subscribedItem')");

For even more clarity your SQLs can look like this:
$sql = "INSERT INTO table SET
            feild1 = {$feild_value1},
            feild2 = {$feild_value2},
            feild3 = {$feild_value3},
            feild4 = {$feild_value4}";
$result = mysql_query($sql);
    .
    .
    .
    .
I know this is not your fish bone but it helps alot in detecting errors a all that.
 Help That Can Be Offered In Programming  Very Urgent! How Can I Do This  Flash Drive (help)  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.