Forum Moderators: coopster
I've got a project that requires a pay-pal payment button be generated for a varying amount of money (depending upon the type of service the user selects) and then embedded into an email that would be sent to the requesting party.
Question 1:
Is it possible to program a pay-pal button (for a variable amount of money) via php?
Question 2:
If question 1 is "Yes", then is it then possible to embed this pay-pal button into a PLAIN TEXT email so that when the user gets the email, they can just click on the pay-pal button to pay whatever fee is required?
Any and all guidance greatly appreciated!
Neophyte
However, to put it in an email, you will have to output an HTML email, as an anchor/link . . . is HTML.
$headers = "From: $from\r\n"; // Preformat as "company" <email>
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $email_subj, $emailbody, $headers);
Thanks so much for your reply - this gives me hope.
So, I do have to format the email as HTML in order to use a linked paypal button image - okay, not so much of an issue there.
With that question satisfied, can you (or someone) guide me to a tutorial that explains how to program a paypal button?
I've looked around the paypal site without much luck. There are a number of scripts/classes available via a google but I would be grateful for a recommendation of one that you/others have used that is easy to implement.
Thanks again to all.
Neophyte
Here's one on a current project for an emailed "donations" button - note the cmd is _donations. I *think* the cmd for purchases is _xclick (check it out.)
<p style="text-align: center">
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=[PAYEE EMAIL OR ACCOUNT NAME]&item_name=Title+of+Your+Item&return=http://www.example.com/thank-you.html&cancel_return=http://www.example.com/transaction-cancelled.html"><img src="http://www.example.com/images/paypal-donate.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"></a>
</p>
Notes on bolded:
- The return url and cancel URL doesn't have to be a static file. It can be a script with any number of parameters, but you must encode the ? and any &'s if you use this. %3F is ?, %26 is &. This is the best method to use if you want to do something with the database on return to the site, or customize the thank you message.
return=some-script%3Frecord_id=1234%26amp;success=1
- You can link to paypal's buttons, but I find it more reliable to store a local copy on your site and link to that button.
- The payPal generated code will most likely not create entities for ampersands. Be sure to change all & to & if you want valid code (not that it matters in an email, it's just a good habit to form for all URL's.)
- Don't leave white space around img when anchoring it:
<a>
<img>
</a>
Even when you set border="0", this causes an annoying little blue line immediately after the image. this is why my example is all run together.
I have adapted it like so.
<p style="text-align: center">
<a href="https://www.paypal.co.uk/cgi-bin/webscr?cmd=_cart&business=example@example.co.uk&item_name=<? echo $Stitle?>&item_number=<? echo $Sstockcode ?>&amount=<? echo $Sprice ?>&currency_code=GBP&add=1&return=http://www.example.co.uk/thankyou.html&cancel_return=http://www.example.co.uk/cancel.html"><img src="http://www.example.co.uk/Images/buttons/addtocart.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"></a>
</p>
This works perfect with my paypal settings, even with the dynamic data. I have just tested this code and works how i want, just worried if i have made it unsecure in anyway.
Thanks
Ski442