Forum Moderators: coopster

Message Too Old, No Replies

Pay Pal Button in php-generated email

Email is formatted at text

         

neophyte

5:28 am on Mar 6, 2009 (gmt 0)

10+ Year Member



Hello All -

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

rocknbil

4:32 pm on Mar 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you can dynamically create a payPal button as a linked image, but it won't work as a form. This is because an offline mail client doesn't submit the way a browser does. If you use a link, be sure to encode special characters.

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);

neophyte

2:20 am on Mar 7, 2009 (gmt 0)

10+ Year Member



Hi Rockinbil -

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

rocknbil

3:01 am on Mar 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just log in to your payPal account, go to the button generator, and generate a "template" to modify to suit your taste.

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&amp;business=[PAYEE EMAIL OR ACCOUNT NAME]&amp;item_name=Title+of+Your+Item&amp;return=http://www.example.com/thank-you.html&amp;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 &amp; 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.

ski442

7:56 pm on Mar 16, 2009 (gmt 0)

10+ Year Member



Hi Guys.
The code you have use to generate the paypal button link is just what i need too, so my question is, if i were to paste this code on my pages is it secure. Can anyone change or hack it?

I have adapted it like so.
<p style="text-align: center">
<a href="https://www.paypal.co.uk/cgi-bin/webscr?cmd=_cart&amp;business=example@example.co.uk&amp;item_name=<? echo $Stitle?>&amp;item_number=<? echo $Sstockcode ?>&amp;amount=<? echo $Sprice ?>&amp;currency_code=GBP&amp;add=1&amp;return=http://www.example.co.uk/thankyou.html&amp;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

eeek

10:04 pm on Mar 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So, I do have to format the email as HTML in order to use a linked paypal button image

Since text/plain doesn't do buttons or images that'd be a yes. But you might also want to generate an alternative in plain text with a url they can click.