Forum Moderators: coopster
Basically I am taking the "Notification of Payment Received" email that PayPal sends out after someone buys something and sending it to a script, where I want to extract the First Name, Last Name, Email Address, and Item Name.
I can divide the message into header, subject, and body. Question: how to extract these variables from the body of the email?
Sample Email
This email confirms that you have received a payment for $999.99 USD from Firstname Lastname (email@a.com).Receipt ID: #*$!x-#*$!x-#*$!x-#*$!x
The number above is the buyer's receipt ID for this transaction. Please retain it for your records so that you will be able to reference this transaction for customer service.--------------------------------------------------------------------------------
View the details of this transaction online
It may take a few moments for this transaction to appear in the Recent Activity list on your Account Overview.
PayPal Shopping Cart ContentsItem Name: Green Widget
Quantity: 1
Total: $999.99 USD
Cart Subtotal: $999.99 USD
Shipping: $0.01 USD
Sales Tax:
Cart Total: $1000.00 USDPayment Details
Total amount: $1000.00 USD
Currency: U.S. Dollars
Transaction ID: 999999999999999
Buyer: Firstname Lastname
I don't even know how to approach extracting these variables... I was thinking, for instance, using a php script that pulls out the whole line beginning with "Item Name:" so that you get "Item Name: Green Widget" and then deletes the "Item Name:" part, trims the string, and sets it to a variable.
Any thoughts on how to do this?
[edited by: MWpro at 8:29 am (utc) on July 9, 2008]
You may not need the \r - I test regex's in a textarea which sometimes changes the rules.
Personally for this I'd just skip the regex. I'd array the lines (exlode("\n",$content)), then walk the array looking for a colon. If a line has a colon, explode that line on the colon.
[1][edited by: eelixduppy at 3:45 pm (utc) on July 11, 2008]