1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| <?php
session_start();
include_once("../config.php");
include_once("paypal.class.php");
// lire le formulaire provenant du système PayPal et ajouter 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= '&$key=$value';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www'.$PayPalMode.'.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www'.$PayPalMode.'.sandbox.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);
if (strcmp ($res, 'VERIFIED') == 0)
{
$post_vars = var_export($_POST, true);
error_log("IPN Result: " . $res, 3, "ipn.log");
error_log("POST_VARS: " . $post_vars, 3, "ipn.log");
$transaction_id = $_POST['txn_id'];
$payerid = $_POST['payer_id'];
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$payeremail = $_POST['payer_email'];
$address1 = $_POST['address1'];
$ville = $_POST['city'];
$cp = $_POST['zip'];
$state = $_POST['state'];
$tel = $_POST['night_phone_a'];
$paymentdate = $_POST['payment_date'];
$paymentstatus = $_POST['payment_status'];
$mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
$otherstuff = json_encode($_POST);
$conn = mysql_connect($db_host,$db_username,$db_password);
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $conn);
// insert in our IPN record table
$query = 'INSERT INTO ibn_table
(itransaction_id,ipayerid,iname,iemail,iadresse1,icp,iville,itel,itransaction_date, ipaymentstatus,ieverything_else)
VALUES('.$transaction_id.','.$payerid.','.$firstname.' '.$lastname.','.$payeremail.','.$adress1.','.$cp.','.$iville.','.$tel.','.$mdate.', '.$paymentstatus.','.$otherstuff.')';
// PHPmailer ------------------------------------------------------------------------------------
require 'PHPMailer/PHPMailerAutoload.php';
//$iemail = $_POST['payer_email'];
$iemail = 'gaborit.elodie@gmail.com';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Set who the message is to be sent from
$mail->setFrom('gaborit.elodie@gmail.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('gaborit.elodie@gmail.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress($iemail);
//Set the subject line
/* Ajout des variables au mail */
$mail->Subject = 'Confirmation de commande chez GDINOX!';
$mail->Body = "Bonjour $lastname $firstname";
//$body = file_get_contents('mail-confirmation-commande.html');
// $body = preg_replace("~{firstname}~i", $firstname, $body);
//$body = preg_replace("~{lastname}~i", $lastname, $body);
$mail->MsgHTML($body);
//Attach an image file
//$mail->addAttachment('images/portfolio/service.jpg');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
else{
$post_vars = var_export($_POST, true);
error_log("IPN Result: " . $res, 3, "ipn.log");
error_log("POST_VARS: " . $post_vars, 3, "ipn.log");
/*
An Invalid IPN *may* be caused by a fraudulent transaction attempt. It's
a good idea to have a developer or sys admin manually investigate any
invalid IPN.
*/
mail('gaborit.elodie@gmail.com', 'Invalid IPN', $req);
}
?> |
Partager