Reply to Script to parse Paypal emails (why does it not work?)

Your name:

Reply:


Posted by Graeme on 11/01/05 23:16

I have been paying a developer to complete what I thought would be
a relatively simple task. Namely, to write/install a script
capable of parsing all of my "PayPal e-mails" (that are sent to me
confirming when a payment has arrived) to a customer database
which he would also need to create.

However, after much time and expense (on my part) this did not
actually happen.

He maintained throughout that everything was fine. During the
testing which was done on his "development server" he claims that
everything was working as expected i.e. all the data was being
extracted and sent to the db.

The problem occurred only when he tried to do the same thing on my
server. Now he was somewhat vague about the whole problem and he
said the following:

<begin quote>
Yes, when outlook (the email client) logs in and retrieves the
ebay/paypal messages it has no problem displaying the data that is
stored in the body portion of those messages.

We had to use outlook to confirm that there was actually some data
in
those messages, because both webdna and php do NOT display any
data in
the body portion of those emails when we use those programs to
retrieve
the same messages.

That's the whole problem here. We KNOW the data is in those
messages,
we simply cannot get webdna or php to retrieve and display this
data.

<end quote>

Apparently, (according to him) for reasons unknown the script
could no longer "see" the data within the body of the email.

FYI he first tried using something called webdna as the scripting
language (once again according to him this would save me time and
consequently money). Then, when this didn't work, he tried again
using PHP.

I have posted the script below in the hope that someone might be
able to be of help.


<?php
include ("../connect.php");

$server = "mail.cashette.com:110/pop3";
$username = "abetterworldcouk@cashette.com";
$pass = "admin123";


function rand_str(){
$size = 15;
$rand_str="";
$feed =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
do{
for ($i=0; $i < $size; $i++){
$rand_str .= substr($feed, rand(0, strlen($feed)-1), 1);
}
$sql = "select transactionID from `order` where
transactionId ='$rand_str'";
$result = mysql_query($sql);
$totalRows = mysql_num_rows($result);

}while ($total > 0);
return $rand_str;
}
function getPlainText($body){
$a = strrev(strstr($body,"Dear ABETTERWORLD.CO.UK LTD,"));
$b = strrev(strstr($a,"2521-swodniw=tesrahc ;lmth/txet
:epyT-tnetnoC"));
return $b;
}

function incomingID($plainText){
$a = explode("
",strstr($plainText,"https://www.paypal.com/uk/vst/id="));
$b = strrev(substr($a[0],33)); ;
$c = substr(strrev(strrchr($b,'-')),0,-1);
return $c;
}
function getbuyer($plainText){
$a = explode(" ",strstr($plainText,"from"));
return $a[1];
}
function getNotesAdded($plainText){
$a = strrev(strstr($plainText,"Note:"));
$b = substr(substr(strrev(strrchr($a,'-')),0,-1),6);
return $b;
}
function getAddressStatus($plainText){
$a = strstr($plainText,"UNCONFIRMED Address");
if (!empty($a)){
return "UNCONFIRMED";
}else{
return "CONFIRMED";
}
}
function getAddress($plainText){
$a = strstr($plainText,"Address");
return $a;
}

$stream = imap_open("\{$server}INBOX",$username,$pass);
$totalMsg = imap_num_msg($stream);
$totalRecentMsg = imap_num_recent($stream);
$totalOrders = 0;



$overview = imap_fetch_overview($stream,"1:$totalMsg",0);

if (is_array($overview)){
foreach ($overview as $value){
$transactionID=rand_str();
$theDate = $value->date;
$body = imap_fetchbody($stream,$value->uid,1,FT_UID);
$plainText = getPlainText($body);
$purchasedFrom = 'visitourwebsite';
$buyer = getBuyer($plainText);
$incomingID = incomingID($plainText);
$notesAdded = getNotesAdded($plainText);
$addressStatus = getAddressStatus($plainText);
//echo getAddress($plainText);

//echo "<br><br>asdddddddd<br><br>";

//orders to order table
/*$sql = ("INSERT INTO `order` ( `id` , `thedate` ,
`transactionID` , `incomingID` , `purchasedFrom` , `datePaid`,
`postagePacking` , `total` , `paymentOption` , `grandTotal` ,
`notes` , `address` , `addressStatus` , `printedInvoice` ,
`printedLabel` , `notesAdded` , `orderPacked` , `orderShipped` ,
`notesOnProcess` , `orderPacked2` , `buyer` )
VALUES ('', '$theDate', '$transactionID', '$incomingID',
'$purchasedFrom', '$theDate', '0', '0', 'paypal', '0', '',
'', '$addressStatus', 'no', 'no', '$notesAdded', 'no', 'no', '',
'no', '$buyer')");
$result = mysql_query($sql);

/*echo strip_tags($body);
echo
"<br><br>test------------------------------------------------------------------------------------------<br><br>";

$handle = fopen("mail.txt","a");
fwrite($handle,strip_tags($body));
fclose($handle);
$tempBuyer = explode(" ",strstr($body,"Address:"));
$buyer = $tempBuyer[1] ." ". $tempBuyer[2];

echo $buyer;
$address = "";
$tempAddStat = explode(" ",strstr($body,"Status:"));
$addStatus = $tempAddStat[1];
echo $addStatus;
$tempItemNo = explode(" ",strstr($body,"Subtotal"));
$itemNo = $tempItemNo[1];
$tempItemName = explode(" ",strstr($body,"Subtotal"));
foreach($tempItemName as $value){
echo "$value <br>";
}
//echo $itemNo;
$tempGrandTotal = explode(" ",strstr($body,"eBay Instant Payment
of"));
$grandTotal = $tempGrandTotal[3];
echo $grandTotal;
$tempPostage = explode(" ",strstr($body,"(includes any seller
packing fees)"));
$postage = $tempPostage[5];
//$total = $grandTotal - $postage;
echo "<br><br>";
*/
}
}




echo "Total no of message order is : $totalOrders";
echo "Total no of recent messages is: $totalRecentMsg";
echo "Total no. of msgs in mailbox is : $totalMsg";
imap_close($stream);
?>



..

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация