From 34d6515c960d5c3c2d4e9256756b003206e067c5 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 17:59:17 -0500 Subject: [PATCH 01/32] added html and unicode email support added a send_email function to simplify sending html emails with added unicode support --- php/example_usage_advanced.php | 48 +++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index b8777d8..7729c81 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -8,8 +8,10 @@ // Set this to true to send a confirmation email: $send_confirmation_email = true; -$confirmation_email_address = "My Name "; -$from_email_address = "My Name "; +$confirmation_email_name = "My Name"; +$confirmation_email_address = "my_email_address@gmail.com"; +$from_email_name = "My Name"; +$from_email_address = "my_email_address@gmail.com"; // Set this to true to save a log file: $save_log_file = true; @@ -20,7 +22,7 @@ -require('PaypalIPN.php'); +require("PaypalIPN.php"); use PaypalIPN; $ipn = new PaypalIPN(); if ($enable_sandbox) { @@ -53,6 +55,33 @@ $timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; $dated_log_file_dir = $log_file_dir . "/" . $year . "/" . $month; +function send_email($name = "", $address = null, $subject = "", $body = "", $from_name = null, $from_address = null, $html = true) { + if (is_null($address)) { + return false; + } + if (is_null($from_name)) { + $from_name = $GLOBALS["from_email_name"]; + } + if (is_null($from_address)) { + $from_address = $GLOBALS["from_email_address"]; + } + $send_email_to = "=?UTF-8?B?" . base64_encode($name) . "?= <" . $address . ">"; + $send_email_header = "MIME-Version: 1.0" . "\r\n"; + if ($html) { + $body = "" . $subject . "" . $body . ""; + $send_email_header .= "Content-type: text/html; charset=UTF-8" . "\r\n"; + } else { + $send_email_header .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; + } + $send_email_header .= "To: " . $send_email_to . "\r\n"; + $send_email_header .= "From: " . "=?UTF-8?B?" . base64_encode($from_name) . "?= <" . $from_address . ">" . "\r\n"; + return mail($send_email_to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $body, $send_email_header); +} + +function send_plain_email($name = "", $address = null, $subject = "", $body = "", $from_name = null, $from_address = null, $html = false) { + return send_email($name, $address, $subject, $body, $from_name, $from_address, $html); +} + $paypal_ipn_status = "VERIFICATION FAILED"; if ($verified) { $paypal_ipn_status = "RECEIVER EMAIL MISMATCH"; @@ -66,10 +95,11 @@ // This is an example for sending an automated email to the customer when they purchases an item for a specific amount: if ($_POST["item_name"] == "Example Item" && $_POST["mc_gross"] == 49.99 && $_POST["mc_currency"] == "USD" && $_POST["payment_status"] == "Completed") { - $email_to = $_POST["first_name"] . " " . $_POST["last_name"] . " <" . $_POST["payer_email"] . ">"; + $email_name = $_POST["first_name"] . " " . $_POST["last_name"]; + $email_address = $_POST["payer_email"]; $email_subject = $test_text . "Completed order for: " . $_POST["item_name"]; - $email_body = "Thank you for purchasing " . $_POST["item_name"] . "." . "\r\n" . "\r\n" . "This is an example email only." . "\r\n" . "\r\n" . "Thank you."; - mail($email_to, $email_subject, $email_body, "From: " . $from_email_address); + $email_body = "

Thank you for purchasing " . $_POST["item_name"] . ".

This is an example email only.

Thank you.

"; + send_email($email_name, $email_address, $email_subject, $email_body); } @@ -114,7 +144,11 @@ if ($send_confirmation_email) { // Send confirmation email - mail($confirmation_email_address, $test_text . "PayPal IPN : " . $paypal_ipn_status, "paypal_ipn_status = " . $paypal_ipn_status . "\r\n" . "paypal_ipn_date = " . $timestamp . "\r\n" . $data_text, "From: " . $from_email_address); + $email_name = $confirmation_email_name; + $email_address = $confirmation_email_address; + $email_subject = $test_text . "PayPal IPN : " . $paypal_ipn_status; + $email_body = "paypal_ipn_status = " . $paypal_ipn_status . "\r\n" . "paypal_ipn_date = " . $timestamp . "\r\n" . $data_text; + send_plain_email($email_name, $email_address, $email_subject, $email_body); } // Reply with an empty 200 response to indicate to paypal the IPN was received correctly From fc4ae605de4ee9a7d786a31cc237eeade27ca972 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 18:20:42 -0500 Subject: [PATCH 02/32] sort the keys for $_POST sort the keys for $_POST alphabetically before printing out the values --- php/example_usage_advanced.php | 1 + 1 file changed, 1 insertion(+) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 7729c81..68f6546 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -30,6 +30,7 @@ } $verified = $ipn->verifyIPN(); +ksort($_POST); $data_text = ""; foreach ($_POST as $key => $value) { $data_text .= $key . " = " . $value . "\r\n"; From 4d06ebb44970661ef641e40608491e7224d19596 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 18:22:07 -0500 Subject: [PATCH 03/32] sort the keys for $_POST sort the keys for $_POST alphabetically before printing out the values --- php/example_usage_advanced.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 68f6546..1882af1 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -30,8 +30,8 @@ } $verified = $ipn->verifyIPN(); -ksort($_POST); $data_text = ""; +ksort($_POST); foreach ($_POST as $key => $value) { $data_text .= $key . " = " . $value . "\r\n"; } From 48a63181e970b989d1e897024e6447a8d47e029f Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 19:11:28 -0500 Subject: [PATCH 04/32] Removed sort Removed sort, because it should be added to PaypalIPN.php --- php/example_usage_advanced.php | 1 - 1 file changed, 1 deletion(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 1882af1..7729c81 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -31,7 +31,6 @@ $verified = $ipn->verifyIPN(); $data_text = ""; -ksort($_POST); foreach ($_POST as $key => $value) { $data_text .= $key . " = " . $value . "\r\n"; } From 4238eecd8ed9ffcc8da99004845dd1f1c727284f Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 20:06:27 -0500 Subject: [PATCH 05/32] Added option to use verified decoded data Added option to use verified decoded data from a return on the verifyIPN function in PaypalIPN.php --- php/example_usage_advanced.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 7729c81..91ff085 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -30,20 +30,26 @@ } $verified = $ipn->verifyIPN(); +if (is_array($verified)) { + $DATA = $verified; +} else { + $DATA = $_POST; +} + $data_text = ""; -foreach ($_POST as $key => $value) { +foreach ($DATA as $key => $value) { $data_text .= $key . " = " . $value . "\r\n"; } $test_text = ""; -if ($_POST["test_ipn"] == 1) { +if ($DATA["test_ipn"] == 1) { $test_text = "Test "; } // Check the receiver email to see if it matches your list of paypal email addresses $receiver_email_found = false; foreach ($my_email_addresses as $a) { - if (strtolower($_POST["receiver_email"]) == strtolower($a)) { + if (strtolower($DATA["receiver_email"]) == strtolower($a)) { $receiver_email_found = true; break; } @@ -94,21 +100,21 @@ function send_plain_email($name = "", $address = null, $subject = "", $body = "" // https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/ // This is an example for sending an automated email to the customer when they purchases an item for a specific amount: - if ($_POST["item_name"] == "Example Item" && $_POST["mc_gross"] == 49.99 && $_POST["mc_currency"] == "USD" && $_POST["payment_status"] == "Completed") { - $email_name = $_POST["first_name"] . " " . $_POST["last_name"]; - $email_address = $_POST["payer_email"]; - $email_subject = $test_text . "Completed order for: " . $_POST["item_name"]; - $email_body = "

Thank you for purchasing " . $_POST["item_name"] . ".

This is an example email only.

Thank you.

"; + if ($DATA["item_name"] == "Example Item" && $DATA["mc_gross"] == 49.99 && $DATA["mc_currency"] == "USD" && $DATA["payment_status"] == "Completed") { + $email_name = $DATA["first_name"] . " " . $DATA["last_name"]; + $email_address = $DATA["payer_email"]; + $email_subject = $test_text . "Completed order for: " . $DATA["item_name"]; + $email_body = "

Thank you for purchasing " . $DATA["item_name"] . ".

This is an example email only.

Thank you.

"; send_email($email_name, $email_address, $email_subject, $email_body); } } } elseif ($enable_sandbox) { - if ($_POST["test_ipn"] != 1) { + if ($DATA["test_ipn"] != 1) { $paypal_ipn_status = "RECEIVED FROM LIVE WHILE SANDBOXED"; } -} elseif ($_POST["test_ipn"] == 1) { +} elseif ($DATA["test_ipn"] == 1) { $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; } From 0b7599cad6962492dd3266c1f4d03502a168ebdf Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 21:00:32 -0500 Subject: [PATCH 06/32] sort $DATA array sort the keys in the $DATA array --- php/example_usage_advanced.php | 1 + 1 file changed, 1 insertion(+) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 91ff085..a8841a3 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -35,6 +35,7 @@ } else { $DATA = $_POST; } +ksort($DATA); $data_text = ""; foreach ($DATA as $key => $value) { From 9db62205a920e8b4cdb6ebf5b40263b546bf55ff Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 22:46:07 -0500 Subject: [PATCH 07/32] added test text to log file directory --- php/example_usage_advanced.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index a8841a3..33007b7 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -60,7 +60,7 @@ list($year, $month, $day, $hour, $minute, $second, $timezone) = explode(":", date("Y:m:d:H:i:s:T")); $date = $year . "-" . $month . "-" . $day; $timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; -$dated_log_file_dir = $log_file_dir . "/" . $year . "/" . $month; +$dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; function send_email($name = "", $address = null, $subject = "", $body = "", $from_name = null, $from_address = null, $html = true) { if (is_null($address)) { From 613688750675f632e8541ee9b01acc51b98708f4 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 23:10:23 -0500 Subject: [PATCH 08/32] send_email_from --- php/example_usage_advanced.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 33007b7..b9424ee 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -73,6 +73,7 @@ function send_email($name = "", $address = null, $subject = "", $body = "", $fro $from_address = $GLOBALS["from_email_address"]; } $send_email_to = "=?UTF-8?B?" . base64_encode($name) . "?= <" . $address . ">"; + $send_email_from = "=?UTF-8?B?" . base64_encode($from_name) . "?= <" . $from_address . ">"; $send_email_header = "MIME-Version: 1.0" . "\r\n"; if ($html) { $body = "" . $subject . "" . $body . ""; @@ -81,7 +82,7 @@ function send_email($name = "", $address = null, $subject = "", $body = "", $fro $send_email_header .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; } $send_email_header .= "To: " . $send_email_to . "\r\n"; - $send_email_header .= "From: " . "=?UTF-8?B?" . base64_encode($from_name) . "?= <" . $from_address . ">" . "\r\n"; + $send_email_header .= "From: " . $send_email_from . "\r\n"; return mail($send_email_to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $body, $send_email_header); } From fdc2ee7ee01dfeaa3bcab3a9922b8694250c5d0e Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sat, 6 Jan 2018 23:25:39 -0500 Subject: [PATCH 09/32] edit send_confirmation_email --- php/example_usage_advanced.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index b9424ee..598c8ec 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -152,11 +152,7 @@ function send_plain_email($name = "", $address = null, $subject = "", $body = "" if ($send_confirmation_email) { // Send confirmation email - $email_name = $confirmation_email_name; - $email_address = $confirmation_email_address; - $email_subject = $test_text . "PayPal IPN : " . $paypal_ipn_status; - $email_body = "paypal_ipn_status = " . $paypal_ipn_status . "\r\n" . "paypal_ipn_date = " . $timestamp . "\r\n" . $data_text; - send_plain_email($email_name, $email_address, $email_subject, $email_body); + send_plain_email($confirmation_email_name, $confirmation_email_address, $test_text . "PayPal IPN : " . $paypal_ipn_status, "paypal_ipn_status = " . $paypal_ipn_status . "\r\n" . "paypal_ipn_date = " . $timestamp . "\r\n" . $data_text); } // Reply with an empty 200 response to indicate to paypal the IPN was received correctly From da830f0822b01f6bc3a60a64e15ebbb384556a3a Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sun, 7 Jan 2018 01:43:16 -0500 Subject: [PATCH 10/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 598c8ec..e52d1c1 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -152,7 +152,9 @@ function send_plain_email($name = "", $address = null, $subject = "", $body = "" if ($send_confirmation_email) { // Send confirmation email - send_plain_email($confirmation_email_name, $confirmation_email_address, $test_text . "PayPal IPN : " . $paypal_ipn_status, "paypal_ipn_status = " . $paypal_ipn_status . "\r\n" . "paypal_ipn_date = " . $timestamp . "\r\n" . $data_text); + $email_subject = $test_text . "PayPal IPN : " . $paypal_ipn_status; + $email_body = "paypal_ipn_status = " . $paypal_ipn_status . "\r\n" . "paypal_ipn_date = " . $timestamp . "\r\n" . $data_text; + send_plain_email($confirmation_email_name, $confirmation_email_address, $email_subject, $email_body); } // Reply with an empty 200 response to indicate to paypal the IPN was received correctly From 47e4f8129ea46c482d0adc6e418d1f5a076dce5a Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sun, 7 Jan 2018 02:49:06 -0500 Subject: [PATCH 11/32] added option to also log raw un-decoded data --- php/example_usage_advanced.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index e52d1c1..505e7d8 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -17,6 +17,9 @@ $save_log_file = true; $log_file_dir = __DIR__ . "/logs"; +// Set this to true to also log un-decoded data: +$log_raw_data = false; + // Here is some information on how to configure sendmail: // http://php.net/manual/en/function.mail.php#118210 @@ -42,6 +45,21 @@ $data_text .= $key . " = " . $value . "\r\n"; } +$raw_data_text = ""; +if ($log_raw_data) { + $RAW_DATA = array(); + foreach (explode('&', file_get_contents('php://input')) as $keyval) { + $keyval = explode('=', $keyval); + if (count($keyval) == 2) { + $RAW_DATA[$keyval[0]] = $keyval[1]; + } + } + ksort($RAW_DATA); + foreach ($RAW_DATA as $key => $value) { + $raw_data_text .= "RAW: " . $key . " = " . $value . "\r\n"; + } +} + $test_text = ""; if ($DATA["test_ipn"] == 1) { $test_text = "Test "; @@ -146,14 +164,14 @@ function send_plain_email($name = "", $address = null, $subject = "", $body = "" } if ($save_log_file) { // Save data to text file - file_put_contents($dated_log_file_dir . "/" . $test_text . "paypal_ipn_" . $date . ".txt", "paypal_ipn_status = " . $paypal_ipn_status . "\r\n" . "paypal_ipn_date = " . $timestamp . "\r\n" . $data_text . "\r\n", FILE_APPEND); + file_put_contents($dated_log_file_dir . "/" . $test_text . "paypal_ipn_" . $date . ".txt", $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . $data_text . $raw_data_text . "\r\n", FILE_APPEND); } } if ($send_confirmation_email) { // Send confirmation email $email_subject = $test_text . "PayPal IPN : " . $paypal_ipn_status; - $email_body = "paypal_ipn_status = " . $paypal_ipn_status . "\r\n" . "paypal_ipn_date = " . $timestamp . "\r\n" . $data_text; + $email_body = $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . "\r\n" . $data_text . "\r\n" . $raw_data_text; send_plain_email($confirmation_email_name, $confirmation_email_address, $email_subject, $email_body); } From 2748f701d8182a4c13065779be8c82b31ce6ab94 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sun, 7 Jan 2018 02:51:46 -0500 Subject: [PATCH 12/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 505e7d8..d869c6c 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -48,8 +48,8 @@ $raw_data_text = ""; if ($log_raw_data) { $RAW_DATA = array(); - foreach (explode('&', file_get_contents('php://input')) as $keyval) { - $keyval = explode('=', $keyval); + foreach (explode("&", file_get_contents("php://input")) as $keyval) { + $keyval = explode("=", $keyval); if (count($keyval) == 2) { $RAW_DATA[$keyval[0]] = $keyval[1]; } From 29f7ed44274a58d509f417535526ccc940a7c720 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Sun, 7 Jan 2018 13:48:37 -0500 Subject: [PATCH 13/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index d869c6c..ee7a1e5 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -80,16 +80,9 @@ $timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; $dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; -function send_email($name = "", $address = null, $subject = "", $body = "", $from_name = null, $from_address = null, $html = true) { - if (is_null($address)) { - return false; - } - if (is_null($from_name)) { - $from_name = $GLOBALS["from_email_name"]; - } - if (is_null($from_address)) { - $from_address = $GLOBALS["from_email_address"]; - } +function send_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null, $html = true) { + if (is_null($from_name)) { $from_name = $GLOBALS["from_email_name"]; } + if (is_null($from_address)) { $from_address = $GLOBALS["from_email_address"]; } $send_email_to = "=?UTF-8?B?" . base64_encode($name) . "?= <" . $address . ">"; $send_email_from = "=?UTF-8?B?" . base64_encode($from_name) . "?= <" . $from_address . ">"; $send_email_header = "MIME-Version: 1.0" . "\r\n"; @@ -104,7 +97,7 @@ function send_email($name = "", $address = null, $subject = "", $body = "", $fro return mail($send_email_to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $body, $send_email_header); } -function send_plain_email($name = "", $address = null, $subject = "", $body = "", $from_name = null, $from_address = null, $html = false) { +function send_plain_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null, $html = false) { return send_email($name, $address, $subject, $body, $from_name, $from_address, $html); } From cd53dc4725cb0cbfe6cdfdcfce17b5fb61415988 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 8 Jan 2018 15:26:47 -0500 Subject: [PATCH 14/32] looks cleaner --- php/example_usage_advanced.php | 41 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index ee7a1e5..c5b885e 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -4,14 +4,14 @@ $enable_sandbox = true; // Use this to specify all of the email addresses that you have attached to paypal: -$my_email_addresses = array("my_email_address@gmail.com", "my_email_address2@gmail.com", "my_email_address3@gmail.com"); +$my_email_addresses = array("seller@paypalsandbox.com", "seller2@paypalsandbox.com", "seller3@paypalsandbox.com"); // Set this to true to send a confirmation email: $send_confirmation_email = true; $confirmation_email_name = "My Name"; -$confirmation_email_address = "my_email_address@gmail.com"; +$confirmation_email_address = "seller@paypalsandbox.com"; $from_email_name = "My Name"; -$from_email_address = "my_email_address@gmail.com"; +$from_email_address = "seller@paypalsandbox.com"; // Set this to true to save a log file: $save_log_file = true; @@ -101,27 +101,13 @@ function send_plain_email($name = "", $address = "", $subject = "", $body = "", return send_email($name, $address, $subject, $body, $from_name, $from_address, $html); } +$process_ipn = false; $paypal_ipn_status = "VERIFICATION FAILED"; if ($verified) { $paypal_ipn_status = "RECEIVER EMAIL MISMATCH"; if ($receiver_email_found) { + $process_ipn = true; $paypal_ipn_status = "Completed Successfully"; - - - // Process IPN - // A list of variables are available here: - // https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/ - - // This is an example for sending an automated email to the customer when they purchases an item for a specific amount: - if ($DATA["item_name"] == "Example Item" && $DATA["mc_gross"] == 49.99 && $DATA["mc_currency"] == "USD" && $DATA["payment_status"] == "Completed") { - $email_name = $DATA["first_name"] . " " . $DATA["last_name"]; - $email_address = $DATA["payer_email"]; - $email_subject = $test_text . "Completed order for: " . $DATA["item_name"]; - $email_body = "

Thank you for purchasing " . $DATA["item_name"] . ".

This is an example email only.

Thank you.

"; - send_email($email_name, $email_address, $email_subject, $email_body); - } - - } } elseif ($enable_sandbox) { if ($DATA["test_ipn"] != 1) { @@ -131,6 +117,23 @@ function send_plain_email($name = "", $address = "", $subject = "", $body = "", $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; } +if ($process_ipn) { + + // Process IPN + // A list of variables are available here: + // https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/ + + // This is an example for sending an automated email to the customer when they purchases an item for a specific amount: + if ($DATA["item_name"] == "something" && $DATA["mc_gross"] == 12.34 && $DATA["mc_currency"] == "USD" && $DATA["payment_status"] == "Completed") { + $email_name = $DATA["first_name"] . " " . $DATA["last_name"]; + $email_address = $DATA["payer_email"]; + $email_subject = $test_text . "Completed order for: " . $DATA["item_name"]; + $email_body = "

Thank you for purchasing " . $DATA["item_name"] . ".

This is an example email only.

Thank you.

"; + send_email($email_name, $email_address, $email_subject, $email_body); + } + +} + if ($save_log_file) { // Create log file directory if (!is_dir($dated_log_file_dir)) { From 6dcce7c76977b30981cd4b422af53ee4eb9daed0 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 8 Jan 2018 15:55:27 -0500 Subject: [PATCH 15/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index c5b885e..daf7336 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -80,6 +80,22 @@ $timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; $dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; +$process_ipn = false; +$paypal_ipn_status = "VERIFICATION FAILED"; +if ($verified) { + $paypal_ipn_status = "RECEIVER EMAIL MISMATCH"; + if ($receiver_email_found) { + $process_ipn = true; + $paypal_ipn_status = "Completed Successfully"; + } +} elseif ($enable_sandbox) { + if ($DATA["test_ipn"] != 1) { + $paypal_ipn_status = "RECEIVED FROM LIVE WHILE SANDBOXED"; + } +} elseif ($DATA["test_ipn"] == 1) { + $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; +} + function send_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null, $html = true) { if (is_null($from_name)) { $from_name = $GLOBALS["from_email_name"]; } if (is_null($from_address)) { $from_address = $GLOBALS["from_email_address"]; } @@ -101,22 +117,6 @@ function send_plain_email($name = "", $address = "", $subject = "", $body = "", return send_email($name, $address, $subject, $body, $from_name, $from_address, $html); } -$process_ipn = false; -$paypal_ipn_status = "VERIFICATION FAILED"; -if ($verified) { - $paypal_ipn_status = "RECEIVER EMAIL MISMATCH"; - if ($receiver_email_found) { - $process_ipn = true; - $paypal_ipn_status = "Completed Successfully"; - } -} elseif ($enable_sandbox) { - if ($DATA["test_ipn"] != 1) { - $paypal_ipn_status = "RECEIVED FROM LIVE WHILE SANDBOXED"; - } -} elseif ($DATA["test_ipn"] == 1) { - $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; -} - if ($process_ipn) { // Process IPN From 3bb2b99c01c01ef056f0cd359fd6e92cc40c356d Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 8 Jan 2018 15:58:13 -0500 Subject: [PATCH 16/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index daf7336..c5b885e 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -80,22 +80,6 @@ $timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; $dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; -$process_ipn = false; -$paypal_ipn_status = "VERIFICATION FAILED"; -if ($verified) { - $paypal_ipn_status = "RECEIVER EMAIL MISMATCH"; - if ($receiver_email_found) { - $process_ipn = true; - $paypal_ipn_status = "Completed Successfully"; - } -} elseif ($enable_sandbox) { - if ($DATA["test_ipn"] != 1) { - $paypal_ipn_status = "RECEIVED FROM LIVE WHILE SANDBOXED"; - } -} elseif ($DATA["test_ipn"] == 1) { - $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; -} - function send_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null, $html = true) { if (is_null($from_name)) { $from_name = $GLOBALS["from_email_name"]; } if (is_null($from_address)) { $from_address = $GLOBALS["from_email_address"]; } @@ -117,6 +101,22 @@ function send_plain_email($name = "", $address = "", $subject = "", $body = "", return send_email($name, $address, $subject, $body, $from_name, $from_address, $html); } +$process_ipn = false; +$paypal_ipn_status = "VERIFICATION FAILED"; +if ($verified) { + $paypal_ipn_status = "RECEIVER EMAIL MISMATCH"; + if ($receiver_email_found) { + $process_ipn = true; + $paypal_ipn_status = "Completed Successfully"; + } +} elseif ($enable_sandbox) { + if ($DATA["test_ipn"] != 1) { + $paypal_ipn_status = "RECEIVED FROM LIVE WHILE SANDBOXED"; + } +} elseif ($DATA["test_ipn"] == 1) { + $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; +} + if ($process_ipn) { // Process IPN From ffa4a0030fa4c5cbf0aa0cda7a3a5f8b00b1a110 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 8 Jan 2018 16:02:26 -0500 Subject: [PATCH 17/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index c5b885e..daf7336 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -80,6 +80,22 @@ $timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; $dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; +$process_ipn = false; +$paypal_ipn_status = "VERIFICATION FAILED"; +if ($verified) { + $paypal_ipn_status = "RECEIVER EMAIL MISMATCH"; + if ($receiver_email_found) { + $process_ipn = true; + $paypal_ipn_status = "Completed Successfully"; + } +} elseif ($enable_sandbox) { + if ($DATA["test_ipn"] != 1) { + $paypal_ipn_status = "RECEIVED FROM LIVE WHILE SANDBOXED"; + } +} elseif ($DATA["test_ipn"] == 1) { + $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; +} + function send_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null, $html = true) { if (is_null($from_name)) { $from_name = $GLOBALS["from_email_name"]; } if (is_null($from_address)) { $from_address = $GLOBALS["from_email_address"]; } @@ -101,22 +117,6 @@ function send_plain_email($name = "", $address = "", $subject = "", $body = "", return send_email($name, $address, $subject, $body, $from_name, $from_address, $html); } -$process_ipn = false; -$paypal_ipn_status = "VERIFICATION FAILED"; -if ($verified) { - $paypal_ipn_status = "RECEIVER EMAIL MISMATCH"; - if ($receiver_email_found) { - $process_ipn = true; - $paypal_ipn_status = "Completed Successfully"; - } -} elseif ($enable_sandbox) { - if ($DATA["test_ipn"] != 1) { - $paypal_ipn_status = "RECEIVED FROM LIVE WHILE SANDBOXED"; - } -} elseif ($DATA["test_ipn"] == 1) { - $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; -} - if ($process_ipn) { // Process IPN From b2251aec05c87519643137a34072971c960f8fe7 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 8 Jan 2018 16:14:16 -0500 Subject: [PATCH 18/32] edit to send_plain_email --- php/example_usage_advanced.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index daf7336..92d3e3b 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -113,8 +113,8 @@ function send_email($name = "", $address = "", $subject = "", $body = "", $from_ return mail($send_email_to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $body, $send_email_header); } -function send_plain_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null, $html = false) { - return send_email($name, $address, $subject, $body, $from_name, $from_address, $html); +function send_plain_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null) { + return send_email($name, $address, $subject, $body, $from_name, $from_address, false); } if ($process_ipn) { From 32ca99f950ef62b5e9bc95033545c5512400ec1c Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 8 Jan 2018 16:53:05 -0500 Subject: [PATCH 19/32] edit send_email --- php/example_usage_advanced.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 92d3e3b..5216768 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -96,7 +96,7 @@ $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; } -function send_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null, $html = true) { +function send_email($name, $address, $subject, $body, $from_name = null, $from_address = null, $html = true) { if (is_null($from_name)) { $from_name = $GLOBALS["from_email_name"]; } if (is_null($from_address)) { $from_address = $GLOBALS["from_email_address"]; } $send_email_to = "=?UTF-8?B?" . base64_encode($name) . "?= <" . $address . ">"; @@ -113,7 +113,7 @@ function send_email($name = "", $address = "", $subject = "", $body = "", $from_ return mail($send_email_to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $body, $send_email_header); } -function send_plain_email($name = "", $address = "", $subject = "", $body = "", $from_name = null, $from_address = null) { +function send_plain_email($name, $address, $subject, $body, $from_name = null, $from_address = null) { return send_email($name, $address, $subject, $body, $from_name, $from_address, false); } From dad1f8c290ca3b64887d607272fdec34b91ab513 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 8 Jan 2018 17:02:34 -0500 Subject: [PATCH 20/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 5216768..5cb5d9d 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -25,6 +25,8 @@ +date_default_timezone_set("America/Los_Angeles"); +list($year, $month, $day, $hour, $minute, $second, $timezone) = explode(":", date("Y:m:d:H:i:s:T")); require("PaypalIPN.php"); use PaypalIPN; $ipn = new PaypalIPN(); @@ -65,6 +67,10 @@ $test_text = "Test "; } +$date = $year . "-" . $month . "-" . $day; +$timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; +$dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; + // Check the receiver email to see if it matches your list of paypal email addresses $receiver_email_found = false; foreach ($my_email_addresses as $a) { @@ -74,12 +80,6 @@ } } -date_default_timezone_set("America/Los_Angeles"); -list($year, $month, $day, $hour, $minute, $second, $timezone) = explode(":", date("Y:m:d:H:i:s:T")); -$date = $year . "-" . $month . "-" . $day; -$timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; -$dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; - $process_ipn = false; $paypal_ipn_status = "VERIFICATION FAILED"; if ($verified) { From 273c7d5feb3cc516003b9f7c22fc539dc7626aa9 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 8 Jan 2018 17:06:48 -0500 Subject: [PATCH 21/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 1 + 1 file changed, 1 insertion(+) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 5cb5d9d..a69a239 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -27,6 +27,7 @@ date_default_timezone_set("America/Los_Angeles"); list($year, $month, $day, $hour, $minute, $second, $timezone) = explode(":", date("Y:m:d:H:i:s:T")); + require("PaypalIPN.php"); use PaypalIPN; $ipn = new PaypalIPN(); From 023ba76e1f2fc4d7e4a62752a99dda1f3aeefeff Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Tue, 9 Jan 2018 19:18:17 -0500 Subject: [PATCH 22/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index a69a239..d34c4ed 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -27,6 +27,8 @@ date_default_timezone_set("America/Los_Angeles"); list($year, $month, $day, $hour, $minute, $second, $timezone) = explode(":", date("Y:m:d:H:i:s:T")); +$date = $year . "-" . $month . "-" . $day; +$timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; require("PaypalIPN.php"); use PaypalIPN; @@ -68,8 +70,6 @@ $test_text = "Test "; } -$date = $year . "-" . $month . "-" . $day; -$timestamp = $date . " " . $hour . ":" . $minute . ":" . $second . " " . $timezone; $dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; // Check the receiver email to see if it matches your list of paypal email addresses From d8794dd2c5d11c191eb070d8dad0a1008fdaf35a Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Wed, 10 Jan 2018 13:35:12 -0500 Subject: [PATCH 23/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index d34c4ed..02485d0 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -98,8 +98,12 @@ } function send_email($name, $address, $subject, $body, $from_name = null, $from_address = null, $html = true) { - if (is_null($from_name)) { $from_name = $GLOBALS["from_email_name"]; } - if (is_null($from_address)) { $from_address = $GLOBALS["from_email_address"]; } + if (is_null($from_name)) { + $from_name = $GLOBALS["from_email_name"]; + } + if (is_null($from_address)) { + $from_address = $GLOBALS["from_email_address"]; + } $send_email_to = "=?UTF-8?B?" . base64_encode($name) . "?= <" . $address . ">"; $send_email_from = "=?UTF-8?B?" . base64_encode($from_name) . "?= <" . $from_address . ">"; $send_email_header = "MIME-Version: 1.0" . "\r\n"; From c4ba82a39829cb2008ecfdef413a5468f71d8c33 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Wed, 10 Jan 2018 16:26:23 -0500 Subject: [PATCH 24/32] removed option for raw data logging --- php/example_usage_advanced.php | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 02485d0..046c012 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -17,9 +17,6 @@ $save_log_file = true; $log_file_dir = __DIR__ . "/logs"; -// Set this to true to also log un-decoded data: -$log_raw_data = false; - // Here is some information on how to configure sendmail: // http://php.net/manual/en/function.mail.php#118210 @@ -50,21 +47,6 @@ $data_text .= $key . " = " . $value . "\r\n"; } -$raw_data_text = ""; -if ($log_raw_data) { - $RAW_DATA = array(); - foreach (explode("&", file_get_contents("php://input")) as $keyval) { - $keyval = explode("=", $keyval); - if (count($keyval) == 2) { - $RAW_DATA[$keyval[0]] = $keyval[1]; - } - } - ksort($RAW_DATA); - foreach ($RAW_DATA as $key => $value) { - $raw_data_text .= "RAW: " . $key . " = " . $value . "\r\n"; - } -} - $test_text = ""; if ($DATA["test_ipn"] == 1) { $test_text = "Test "; @@ -165,14 +147,14 @@ function send_plain_email($name, $address, $subject, $body, $from_name = null, $ } if ($save_log_file) { // Save data to text file - file_put_contents($dated_log_file_dir . "/" . $test_text . "paypal_ipn_" . $date . ".txt", $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . $data_text . $raw_data_text . "\r\n", FILE_APPEND); + file_put_contents($dated_log_file_dir . "/" . $test_text . "paypal_ipn_" . $date . ".txt", $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . $data_text . "\r\n", FILE_APPEND); } } if ($send_confirmation_email) { // Send confirmation email $email_subject = $test_text . "PayPal IPN : " . $paypal_ipn_status; - $email_body = $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . "\r\n" . $data_text . "\r\n" . $raw_data_text; + $email_body = $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . "\r\n" . $data_text; send_plain_email($confirmation_email_name, $confirmation_email_address, $email_subject, $email_body); } From 140363526e4da9782c405780d9638063bb38094f Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Thu, 11 Jan 2018 17:26:01 -0500 Subject: [PATCH 25/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 046c012..4cdf61b 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -153,9 +153,7 @@ function send_plain_email($name, $address, $subject, $body, $from_name = null, $ if ($send_confirmation_email) { // Send confirmation email - $email_subject = $test_text . "PayPal IPN : " . $paypal_ipn_status; - $email_body = $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . "\r\n" . $data_text; - send_plain_email($confirmation_email_name, $confirmation_email_address, $email_subject, $email_body); + send_plain_email($confirmation_email_name, $confirmation_email_address, $test_text . "PayPal IPN : " . $paypal_ipn_status, $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . $data_text); } // Reply with an empty 200 response to indicate to paypal the IPN was received correctly From f1e85f9d6fb9ad47539c6f8a9811f34ac1168dd7 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Thu, 11 Jan 2018 17:38:55 -0500 Subject: [PATCH 26/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 4cdf61b..431e30d 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -52,8 +52,6 @@ $test_text = "Test "; } -$dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; - // Check the receiver email to see if it matches your list of paypal email addresses $receiver_email_found = false; foreach ($my_email_addresses as $a) { @@ -123,6 +121,7 @@ function send_plain_email($name, $address, $subject, $body, $from_name = null, $ if ($save_log_file) { // Create log file directory + $dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; if (!is_dir($dated_log_file_dir)) { if (!file_exists($dated_log_file_dir)) { mkdir($dated_log_file_dir, 0777, true); From de46530e3ea07f19e9b1211e3ae6790962787d29 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Thu, 11 Jan 2018 17:42:37 -0500 Subject: [PATCH 27/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 431e30d..4464594 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -120,8 +120,8 @@ function send_plain_email($name, $address, $subject, $body, $from_name = null, $ } if ($save_log_file) { - // Create log file directory $dated_log_file_dir = $log_file_dir . "/" . $test_text . $year . "/" . $test_text . $month; + // Create log file directory if (!is_dir($dated_log_file_dir)) { if (!file_exists($dated_log_file_dir)) { mkdir($dated_log_file_dir, 0777, true); From 89773eeb58e2da231e141339f39f373ba6dbb7ab Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Thu, 11 Jan 2018 20:20:55 -0500 Subject: [PATCH 28/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 4464594..b20e61b 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -4,14 +4,14 @@ $enable_sandbox = true; // Use this to specify all of the email addresses that you have attached to paypal: -$my_email_addresses = array("seller@paypalsandbox.com", "seller2@paypalsandbox.com", "seller3@paypalsandbox.com"); +$my_email_addresses = array("my_email_address@example.com", "my_email_address2@example.com", "my_email_address3@example.com"); // Set this to true to send a confirmation email: $send_confirmation_email = true; $confirmation_email_name = "My Name"; -$confirmation_email_address = "seller@paypalsandbox.com"; +$confirmation_email_address = "my_email_address@example.com"; $from_email_name = "My Name"; -$from_email_address = "seller@paypalsandbox.com"; +$from_email_address = "my_email_address@example.com"; // Set this to true to save a log file: $save_log_file = true; From 405b142ff3fab289e6b488cde852fae482ff10bd Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Thu, 11 Jan 2018 20:42:55 -0500 Subject: [PATCH 29/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index b20e61b..a219bb8 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -10,6 +10,8 @@ $send_confirmation_email = true; $confirmation_email_name = "My Name"; $confirmation_email_address = "my_email_address@example.com"; + +// Set these to the name and email address that you are sending emails from: $from_email_name = "My Name"; $from_email_address = "my_email_address@example.com"; From 8e2df88f06647258b2e6a146c49f9349373fdcba Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 14 Oct 2019 17:06:48 -0400 Subject: [PATCH 30/32] removed duplicate to field to prevent sending duplicate emails removed duplicate "To:" field to prevent sending duplicate emails --- php/example_usage_advanced.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index a219bb8..c8a82e7 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -80,23 +80,18 @@ } function send_email($name, $address, $subject, $body, $from_name = null, $from_address = null, $html = true) { - if (is_null($from_name)) { - $from_name = $GLOBALS["from_email_name"]; - } - if (is_null($from_address)) { - $from_address = $GLOBALS["from_email_address"]; - } + if (is_null($from_name)) { $from_name = $GLOBALS["from_email_name"]; } + if (is_null($from_address)) { $from_address = $GLOBALS["from_email_address"]; } $send_email_to = "=?UTF-8?B?" . base64_encode($name) . "?= <" . $address . ">"; $send_email_from = "=?UTF-8?B?" . base64_encode($from_name) . "?= <" . $from_address . ">"; - $send_email_header = "MIME-Version: 1.0" . "\r\n"; + $send_email_header = "MIME-Version: 1.0"; if ($html) { $body = "" . $subject . "" . $body . ""; - $send_email_header .= "Content-type: text/html; charset=UTF-8" . "\r\n"; + $send_email_header .= "\r\n" . "Content-type: text/html; charset=UTF-8"; } else { - $send_email_header .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; + $send_email_header .= "\r\n" . "Content-type: text/plain; charset=UTF-8"; } - $send_email_header .= "To: " . $send_email_to . "\r\n"; - $send_email_header .= "From: " . $send_email_from . "\r\n"; + $send_email_header .= "\r\n" . "From: " . $send_email_from; return mail($send_email_to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $body, $send_email_header); } From 3927d0110dd30711b0f909d467cc424dc8053a91 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 14 Oct 2019 17:46:02 -0400 Subject: [PATCH 31/32] renamed mail functions to be simpler renamed mail functions to be simpler --- php/example_usage_advanced.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index c8a82e7..6dee235 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -79,7 +79,7 @@ $paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE"; } -function send_email($name, $address, $subject, $body, $from_name = null, $from_address = null, $html = true) { +function send_email($name, $address, $subject, $body, $from_name = null, $from_address = null, $html = false) { if (is_null($from_name)) { $from_name = $GLOBALS["from_email_name"]; } if (is_null($from_address)) { $from_address = $GLOBALS["from_email_address"]; } $send_email_to = "=?UTF-8?B?" . base64_encode($name) . "?= <" . $address . ">"; @@ -95,8 +95,8 @@ function send_email($name, $address, $subject, $body, $from_name = null, $from_a return mail($send_email_to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $body, $send_email_header); } -function send_plain_email($name, $address, $subject, $body, $from_name = null, $from_address = null) { - return send_email($name, $address, $subject, $body, $from_name, $from_address, false); +function send_html_email($name, $address, $subject, $body, $from_name = null, $from_address = null) { + return send_email($name, $address, $subject, $body, $from_name, $from_address, true); } if ($process_ipn) { @@ -149,7 +149,7 @@ function send_plain_email($name, $address, $subject, $body, $from_name = null, $ if ($send_confirmation_email) { // Send confirmation email - send_plain_email($confirmation_email_name, $confirmation_email_address, $test_text . "PayPal IPN : " . $paypal_ipn_status, $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . $data_text); + send_email($confirmation_email_name, $confirmation_email_address, $test_text . "PayPal IPN : " . $paypal_ipn_status, $paypal_ipn_status . "\r\n" . $timestamp . "\r\n" . $data_text); } // Reply with an empty 200 response to indicate to paypal the IPN was received correctly From ef042b175563841f93469e4a0518efad104f87b9 Mon Sep 17 00:00:00 2001 From: BigRedBot Date: Mon, 14 Oct 2019 18:03:25 -0400 Subject: [PATCH 32/32] Update example_usage_advanced.php --- php/example_usage_advanced.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/example_usage_advanced.php b/php/example_usage_advanced.php index 6dee235..b9e4c05 100644 --- a/php/example_usage_advanced.php +++ b/php/example_usage_advanced.php @@ -111,7 +111,7 @@ function send_html_email($name, $address, $subject, $body, $from_name = null, $f $email_address = $DATA["payer_email"]; $email_subject = $test_text . "Completed order for: " . $DATA["item_name"]; $email_body = "

Thank you for purchasing " . $DATA["item_name"] . ".

This is an example email only.

Thank you.

"; - send_email($email_name, $email_address, $email_subject, $email_body); + send_html_email($email_name, $email_address, $email_subject, $email_body); } }