Voucher question

C

chrismitchell

Guest
Ok people, I need a bit of PHP mastery help..

I have an online shop that i've developed for a cookery school (Inspired Gourmet | Professional Cookery Courses | Milton Keynes), It uses WP e-commerce to sell items etc. Now she wants to have the ability to sell vouchers dynamically through the system, which it doesn't allow unfortunately. What I need is a way of dynamically calling some checkout details from the e-commerce plugin (one being the recipients name, the other being the message and the final one being the email address to send the voucher to). What i need is a way of making an email that will dynamically grab this information from the database (which is within a table in the mySQL database from that specific session) and create an HTML email which looks like a voucher (with a graphic logo and border etc etc) and then it will be emailed to the recipient.

I know Harry made a letter to Santa site which is sort of like what I need to do, but this needs to be done after payment has been made for the specific amount (one is £55, one is £65 and one is £135).

Any help would be great.

Chris
 
A bit of both really Harry... I just need it to dynamically make the Voucher and send it to the purchaser of the voucher... Its an odd thing i'm trying to do, but I have the option of a download file / link after purchase which could do the voucher into a webpage (and email it to you at the same time sort of thing) and allow the user to print the voucher...

Its annoying that the Voucher options within the actual plugin don't work in that way (its just coupon codes LOL).

Do you think this is doable Harry?
 
It is doable, but beyond my scope. Ideally you'd have it built into a custom framework as opposed to hacking it into (the notoriously poorly coded) Wordpress.

Sorry I can't be of more help (unless you need someone to build the email haha).
 
yeah Jaz I know the table and the row names, the problem is that it would be from that session, as they would do the payment in Paypal then once the paypal confirmation finishes is would need to either email the ticket that can be either in HTML or PDF (i dont mind either really)

I hope that makes sense?

I can drop you a more descriptive email if you would like more info Jaz?
 
Okay I think I get it, small brain struggles at times. :)

Okay writing this off the cuff so you may have to go with it/tell me what your error is. I will also leave it up to you to place the files in includes if you want to.

Right so along as you are running on Apache we will start off by setting what is known as environmental variables. If you don't know environmental variables are variables that are available to every page via the $_SERVER array. But they are great for securing secure information in such as DB info.

This is because people who are on the same server as you can read any of your files so if you had your connection code with your password, db, user name etc...in they would see them, this case they just see $_SERVER['blar blar'] which is useless to them.

So open up your .htaccess file and place this directive in it:
SetEnv USER yourUserName
SetEnv PASSWORD yourPassword
SetEnv DATABASE yourDatabaseName
SetEnv HOST yourHostName


The your host name directive normal defaults to localhost so unless you know otherwise stick that in there.

Now if you are running Ill's you will have to jump straight to this point and change the server bits to your actual details. Right so now we query the DB and getting the nesercary fields.
<?php
$db=mysqli_connect($_SERVER['HOST'], $_SERVER['USER'], $_SERVER['PASSWORD'], $_SERVER['DATABASE']);

This section connects to the database but brings in your details that we stored in the .htaccess file.

So now we will need some data to know which field it is from and make sure it is secure data.

So:

$clean['user']=""; // Sets the clean variable to nothing.
$clean['user']=strip_tags(preg_replace('#[^A-Za-z0-9 ]#', '', $_POST['username'])); //Sets the clean variable to the $post user name variable, but removes all html tags, and then turns any character that is not a-z or 0-9 or spaces to nothing, meaning we are left with only sterile data
.

Next we query the DB and get the right fields.

$select="SELECT name, message, email FROM table WHERE name=' ". $clean['user'] ."' ";
$query=mysqli_query($db,$select) or die("Error number: 100<br /> Please contact our support staff stating the error number please");
while($row=mysqli_fetch_assoc($query)){
extract($row);


Now we want to send an emil to the email in the database so:

$to=$email;
$subject="Voucher from siteName";
$headers='MIME-Version: 1.0' . "\r\n";
$headers.='Content-type: text/html; charset=iso-8859-1'."\r\n"; //These lines set the email to send html code.
$headers.="From: Your Site <[email protected]>"."\r\n";
$body="
<p>
<img src='http://yourSIte.com/img/someImage,jpg' alt='' />
</p>
<p>
Hi ".$name.",
</p>
<p>
Thank you for shopping at SiteName.<br />
Because we value our customers heres &pound;65 off your next order.
</p>
<p>
All you need to do is enter code <b>Promo1< /b> at the checkout on your next visit.
</p>";
mail($to,$subject,$body,$headers);
?>


And that should be it.

If thats not what you want tell me what I have misunderstood and I'll have a think. :)

Jaz

Key:
Red: PHP
Orange: PHP comments
Purple: .htaccess directives.
 
another monster post mate.. thanks dude i'll give it a try..
 
Back
Top