I have noticed that the page on paypal for the donation button and subscription form look different and I am not sure if the donation button supports ipn or not because someone sent me a link before but it doesn't have any solutions. I am trying to do a similar script for a donation button that will send an email to thank the user for the donation.
<?php
ob_start();
include_once __DIR__.'/header2.php';
if (!$_SESSION['u_uid']) {
echo "<meta http-equiv='refresh' content='0;url=index.php?donation=notlogin'>";
exit();
} else {
include_once __DIR__.'/includes/dbh.php';
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
header("Location: index.php");
exit();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query($_POST));
$response = curl_exec($ch);
curl_close($ch);
if ($response == "VERIFIED" && $_POST['receiver_email'] === "admin@pianocourse101.com") {
$cEmail = strip_tags($_POST['payer_email']);
$firstname = strip_tags($_POST['first_name']);
$lastname = strip_tags($_POST['last_name']);
$price = strip_tags($_POST['mc_gross']);
$currency = strip_tags($_POST['mc_currency']);
$item = strip_tags($_POST['item_number']);
$paymentStatus = strip_tags($_POST['payment_status']);
if ($item == "Donation" && $currency == "USD" && $paymentStatus == "Completed" && $price == 100) {
$sql = "INSERT INTO donation (user_email, firstname, lastname, amount) VALUES (?,?,?,?);";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "sssi", $cEmail, $firstname, $lastname, $price);
mysqli_stmt_execute($stmt);
// Edit this path if PHPMailer is in a different location.
//$mail->SMTPDebug = 2;
include_once __DIR__.'/PHPMailer/Exception.php';
include_once __DIR__.'/PHPMailer/PHPMailer.php';
include_once __DIR__.'/PHPMailer/SMTP.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->CharSet = 'UTF-8';
//$mail->isSMTP(); enable this for localhost and disable for live host???
$mail->isHTML(true);
/*
* Server Configuration
*/
$mail->Host = 'smtp.gmail.com'; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS and 465 for SSL security.
$mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "pianocourseforkids101@gmail.com"; // Your Gmail address.
$mail->Password = "*******"; // Your Gmail login password or App Specific Password.
/*
* Message Configuration
*/
$mail->setFrom('Admin@pianocourse101.com', 'PianoCourse101 Registration'); // Set the sender of the message.
$mail->addAddress($cEmail, 'PianoCourse101 Registration'); // Set the recipient of the message.
$mail->Subject = 'PianoCourse101 Registration'; // The subject of the message.
/*
* Message Content - Choose simple text or HTML email
*/
// Choose to send either a simple text email...
$mail->Body = "Dear $firstname $lastname, <br /></br />
Thank-you for your kind donation towards PianoCourse101!<br /><br />We hope that you will continue to enjoy your time with us and most importantly, we wish you the best in your piano learning.
<br /><br />
From,
<br /><br />
PianoCourse101
"; // Set a plain text body.
// ... or send an email with HTML.
//$mail->msgHTML(file_get_contents('contents.html'));
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body';
// Optional: attach a file
$mail->addAttachment('images/phpmailer_mini.png');
if ($mail->send()) {
echo "<meta http-equiv='refresh' content='0;url=update.php?upgradelevel1monthly=success'>";
exit();
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
}
}
}
?>