I have got some sample code from PayPalTech.com and have edited to fit my needs. Basically all I want to have work is for an email to be sent to the customer after the order is completed. I have edited the php code to fit my needs but for some reason it isn't working anymore now. The original code was meant to just echo all the php variables from the IPN and end it in an email to myself. Here is the code that I have so far.
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0
";
// If testing on Sandbox use:
// $header .= "Host: www.sandbox.paypal.com:443
";
$header .= "Host: www.paypal.com:443
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "
";
// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
//transaction ID
$txn_id = $_POST['txn_id'];
//ATEKDesign
$business = $_POST['business'];
//payer email
$payer_email = $_POST['payer_email'];
//create payer name
$payer_firstname = $_POST['first_name'];
$payer_lastname = $_POST['last_name'];
$payer_name = $payer_firstname . " " . $payer_lastname;
//create payer address
$name = $_POST['address_name'];
$street = $_POST['address_street'];
$city = $_POST['address_city'];
$state = $_POST['address_state'];
$zip = $_POST['address_zip'];
$address = "$name
$street
$city $state $zip";
if (!$fp)
{
// HTTP ERROR
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$mail_From = "From: me@mybiz.com";
$mail_To = "atekdesigns@gmail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = "Hello $payer_ name , thank you for purchasing the $item_name from $buisness , your order ID is as follows: $txn_id; .
We will be using $payer_email to contact you and will be sending you item to $address";
$emailtext = blank;
mail($mail_To, $mail_Subject, $emailtext . "
" . $mail_Body, $mail_From);
}