Jump to content

PHP formtomail and paypal


Sharkadder

Recommended Posts

ok on my website i have a formtomail which i set up for users to sign up to my web hosting plan.currently the user fill's in the form, presses submit, then i get an e-mail sent displaying the results in which the user filled in.I have also added some error checking and validation etc. to make sure all field's are filled in correctly.Now, when the user presses submit, they get taken to a HTML page that has a continue button, they press that and then get taken to a page where they select their hosting plan.Once selected, they make the payment through paypal and i get sent the invoice. at the end of the payment, the user then get's taken to a page called "successful.html" .To elimate people signing up and then not paying, how can i modify my formtomail so that it only get's sent to me after the payment has been made?At the minute if somebody sign's up and doesn't pay within a day, i send them an e-mail with a link for them to pay. What i need is to somehow modify my php code, so that when the user completes payment and goes to sucessful.html, they will press a button there and then the e-mail with the data will get sent to me.It would also be nice to include the plan the person select's in wit the e-mail, currently the user selects a plan by pressing the required button out of a selection of 3. How i could include this in my formtomail and send them to the required paypal page by this i am not sure.i may of confused you abit of i'll tell you what i currently have, then explain what i am now trying to do.CURRENT SETUP ORDER(1)user clicks sign up---->(2)user types in details on FormtoMail----->(2)if details are incorrect once submit is pressed, user goes back to stage(2) ---->(3)if details are correct, user's details get sent to me by email----->(4)user selects hosting plan they wish to choose and make a payment to me via paypal---->(5)user then get's taken to sucessful page and transaction is completed.NEEDED SETUP ORDER(1)user clicks sign up---->(2)user types in details on FormtoMail----->(2)if details are incorrect once submit is pressed, user goes back to stage(2) ---->(3)if details are correct, user selects hosting plan they wish to choose---->(4)payment is made to me via paypal---->(5)user then get's taken to sucessful page, they press complete, FormtoMail data is then sent to me and transaction is completed.the thing i don't get is how i could get the data sent to me after the person has paid through paypal.p.s. sucessfull.html can be a php page if needed.thanks, hope soembody can help me abit or give me a few tips

Link to comment
Share on other sites

The data that Paypal sends back to your page will indicate whether or not the transaction succeeded. You can use that data to determine if you need to send yourself an email. The page will need to be a PHP page so that it can send the mail. It might be best to save the customer information into a database and use a cookie that will contain the database ID or something, and when they come back from Paypal you can look up their information in the database and send the email, along with whatever information from Paypal you want to send as well.

Link to comment
Share on other sites

The data that Paypal sends back to your page will indicate whether or not the transaction succeeded. You can use that data to determine if you need to send yourself an email. The page will need to be a PHP page so that it can send the mail. It might be best to save the customer information into a database and use a cookie that will contain the database ID or something, and when they come back from Paypal you can look up their information in the database and send the email, along with whatever information from Paypal you want to send as well.
so what your saying is this:i create a database, when the user sign's up the main part of thr form, all the data goes into the database, they then pay and when user presses the plan they wish to choose, that choice gets added into the database, when transaction is completed in paypal they press confirm, if they don't press confirm the data in the database get's wiped, if they do press confirm, all the data then get's sent to me via formtomail to my e-mail.now what do i use to get formtomail to interact with a database? mysql i can use (since i run a linux server) or i may be able to use ADO aswell.Can you tell me if i am on the right sort of line on what i need to do, if so how could i go about implimenting a database i nwith formtomail? i never done that before.
Link to comment
Share on other sites

That's pretty much it. I wouldn't use formtomail though, I don't know what that is (there are a ton of things with that name), but it's easy enough to do it all yourself. If you haven't used MySQL yet with PHP, check the MySQL reference:http://www.php.net/manual/en/ref.mysql.phpThe example on this page is a SELECT query so they print the results, but you can send any SQL query to the database (insert, update, delete, etc). There are a few MySQL functions to use, like mysql_connect, mysql_select_db, mysql_query, etc. All of them are listed on that page. For sending email, you can use the mail function:http://www.php.net/manual/en/function.mail.phpThis will take a little trial and error, you will want to set up some transactions for $0.01 or something and pay for them yourself to test and see what Paypal sends back to your page when you do different things. When you know the data that is coming back then you can decide how you want to use it.

Link to comment
Share on other sites

ok thanks, a mate and me once got ASP to connect to a MS SQL database on a windows 2003 server but i am yet to try linux, this will be interesting.p.s. form to mail just alolows user to type in some data, once submit is pressed the data goes to the corrisponding e-mail you typed in when programming.

Link to comment
Share on other sites

If you can get ASP to talk to SQL Server with connection strings and whatnot then PHP/MySQL will be a breeze. Assuming you're using a hosted account, everything is probably already set up for you. You'll need to go into your hosting control panel and create a database (how you do that will depend on the host), then use a tool like phpMyAdmin to set up all the tables. Once you have that set up, then you use 2 functions to connect to the database, and a third function to send queries to it. If you are using SELECT queries to retrieve data then you use a fourth function to loop through the results. You only need to connect and select the database once on every page.

mysql_connect('server_name', 'user_name', 'password');mysql_select_db('database_name');mysql_query('DELETE FROM table WHERE id=10');$result = mysql_query('SELECT * FROM table');while ($row = mysql_fetch_assoc($result)){  print $row['field_name'];}

Link to comment
Share on other sites

yeah i do have a hosting account. According to my control panel i can create tables etc. through that but i like to program and code.I cannot use ASP as my linux server only allows php. the other stuff i don't know about like cgi,pearl etc.So what i said was right? i store all the info in the database, but how would i tempory store data? what i mean is, the person fill's in the main sign up form, presses a link which goes to paypal, when they go to the sucessful screen, how can i get the database to delete the data if the submit button is not pressed? I'm not sure but i don't think you can store data in a database on temp until an action is done, i may be confusing you here but you can probably gather what i mean.Because user will be going to paypal and then back to my server to complete the transaction, i will need to somehow temp store the data into the database, if submit is not pressed i need a way of removing it, obviously if it is pressed then it gets stored.any ideas? once i got that sorted i can probably get something started.

Link to comment
Share on other sites

Yeah, there's not a temporary database thing. You would need to put a timestamp on it and have some code that will delete old entries. So if you make a field called "last_action" and set it to be an INT, then you can use the PHP time() function to generate the current timestamp to stick in that field. You can use this to delete everything older then a day:

mysql_query("DELETE FROM table WHERE last_action < " . time() - 86400);

You can either put that query on every page so any time anyone loads any page it deletes old entries, or you can use a random number to say that 5% of the time it will delete old entries, or have a link that you manually click on to delete them. Or, set up a cron job (scheduled task) that gets run every so often to delete them.You could use another solution like a session, which is temporary, but if they start at your site and then go to Paypal and then come back it might not use the same session, I'm not sure. That's why I was saying you could use a cookie to store their database ID that you can look up when they come back, the cookie will last if they leave and come back. The session very well might work though, it uses a cookie for the session ID so that might be exactly what you need. It will time out after 24 minutes though, by default. You would need to set some config options though to make sure the session only uses cookies, and you might want to set the cookie lifetime to something other then the default.http://www.php.net/manual/en/ref.session.p...cookie-lifetime

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...