Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnSubmit - to send an email before going to the next page. 1

Status
Not open for further replies.

Trusts

Programmer
Feb 23, 2005
268
US
HI,

I have a form that posts to PayPal to get payment from buyers on the site. I am trying to send an email too - to the merchant at the same time. The form action goes to the Paypal URL, but if I use a onSubmit function, is there a way to get the email sent from javascript code?
 
You can use Javascript to make a secondary HTTP request before submitting, but you will need a server-side script (Perl, PHP, ASP, etc) to send the email.

There are a number of ways to make that request in Javascript - you may want to look into an AJAX call or setting the src property of a hidden iframe.

Unless this is purely an information email, along the lines of "Someone might be buying these items" or "Survey results from recent purchase", I would caution you against doing this. There is no way to tell whether the person paid for the item (they may very well go to PayPal and close the browser window). If you have a high sales volume it would be very difficult to match payments with whatever important information is in this email.

PayPal offers "Instant Payment Notification" or IPN which allows you to specify a script on your site for PayPal to notify when the transaction is complete and the payment is received. Then you have the PayPal transaction id, cost, amount paid, and additional information if necessary. PayPal provides several shells in various languages which do the proper necessary authentication steps to make sure that the transaction is real and not spoofed. You would just add code to one of those shells that sends your email, now able to say "So-and-so bought these items, prepare to ship them.
 
Few things -

The email is to send all the name, address, and cart info to the merchant. It sounds redundant I know, but there is a business need for this. The emails contain alot more info than can be sent to PayPal. I have tricked PayPal a bit by concatenating a form field name with the entry placed in it - as the PayPal item name, and then just using a 0 for the item amount. This is OK to a point.

I have been trying to get IPN to behave but apparently it is buggy - i see a lot of developers complain about it on the PayPal Dev board. It works - sometimes, which means it is useless if you can't depend on it.

So what I have the merchant doing is matching up the PayPal reports to the emails. The issue was trying to get rid of emails that are dups when a person goes back from the confirmation page to change something on the order form page. Then when they submit it again and go again to the confirm page, another email goes out. That is what is a hassle. You can get three versions of the basically same email, the person might have changed one thing, and you don't know which one is the correct email!

I'll see what I can do with Ajax, that could work. I just wonder if i can forward 50 or more fields to the server using Ajax??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top