Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9016409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:59:18+00:00 2026-06-16T03:59:18+00:00

I have two scripts and want to combine them in one line. I have

  • 0

I have two scripts and want to combine them in one line.
I have marked the line with this comment:’here I need stack-overflow-help’.

First script:
This is the Paypal ipn responder (https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623):

<?php 
// STEP 1: Read POST data
// reading posted data from directly from $_POST causes serialization 
// issues with array data in POST
// reading raw POST data from input stream instead.

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();

foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
     $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}

// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
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_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path 
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');

if( !($res = curl_exec($ch)) ) {
    // error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly

if (strcmp ($res, "VERIFIED") == 0) {
    // check whether 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
    // 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'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];
} 
else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
}
?>

Second script:

This is phpmailer_v5.1 use_gmail.php:

<?php
// example on using PHPMailer with GMAIL

include("class.phpmailer.php");
include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded

$mail             = new PHPMailer();
$body             = 'this is the body of the email';

$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port

$mail->Username   = "yourname@gmail.com";  // GMAIL username
$mail->Password   = "password";            // GMAIL password

$mail->From       = "replyto@yourdomain.com";
$mail->FromName   = "Webmaster";
$mail->Subject    = "This is the subject";
$mail->AltBody    = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap   = 50; // set word wrap

$mail->MsgHTML($body);
$mail->AddReplyTo("replyto@yourdomain.com","Webmaster");
$mail->AddAttachment("/path/to/file.zip");             // attachment
$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment
$mail->AddAddress("username@domain.com","First Last"); //here I need stackoverflow-help
$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}
?>

I have class.smtp and class.phpmailer in the same folder.use_gmail.php is tested and working and sending emails.But only when I write the destination email address in this line:

$mail->AddAddress("username@domain.com","First Last");

I want to send the email to the customer who just made the payment.How can I get the destination e-mail address from Paypal?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:59:20+00:00Added an answer on June 16, 2026 at 3:59 am

    In our ecommerce configuration, we used a trick to make the real user email ( e.g. the one that he used to register into our clients database ) be sent by the IPN responder.

    When a user pays with Paypal, a form is sent to the Paypal system with informations about the amount of the payment, url bridges and so on. Here’s an example:

    <form name="autoPayFormSubmit" id="autoPayFormSubmit" method="post" action="https://securepayments.paypal.com/cgi-bin/acquiringweb"> 
        <input type="hidden" name="cmd" value="_hosted-payment" />
        <input type="hidden" name="subtotal" value="#SUBTOTAL#" />
        <input type="hidden" name="shipping" value="#SHIPCOST#" />
        <input type="hidden" name="business" value="#NUMBEROFBUSINESS#" />
        <input type="hidden" name="paymentaction" value="sale" />
        <input type="hidden" name="custom" value=" ## USE ME TO TRICK THE SYSTEM ##" />
        <input type="hidden" name="currency_code" value="EUR" />
        <input type="hidden" name="shopping_url" value="http://yourwebsite.domain/##" />
        <input type="hidden" name="cbt" value="Go back to the shopping" />
        <input type="hidden" name="notify_url" value="http://yourwebsite.domain/##" />
        <input type="hidden" name="cancel_return" value="http://yourwebsite.domain/##" />
        <input type="hidden" name="return" value="http://yourwebsite.domain/##" />
        <input type="submit" value="PAYPAL SAFE PAYMENT" onmouseover="this.style.backgroundColor='#CEE4F2';" onmouseout="this.style.backgroundColor='#EAF2F6';" style="font-weight: bold; font-size: 14px; padding: 10px 5px; border-radius: 10px; background: #EAF2F6 none no-repeat scroll 0 0; box-shadow: 3px 3px 5px #888; cursor:pointer;">
    </form>
    

    The “trick” is to send via the “custom” input the email of the user registered into the system, along with other useful data.
    In our ecommerce, for example, we serialize an array with the user email, the order id, and other “non-compromising” values. After it has been serialized, we encode it with a crypt class we created on our own ( or you can simply use the mcrypt extension of PHP ).

    Once you get the IPN response, you will also get the

    $custom_encrypted_serialized_variables = $_POST['custom'];
    

    So, you can replace your IPN listener code at step 3 with the following:

    ...
    ...
    // STEP 3: Inspect IPN validation result and act accordingly
    if (strcmp ($res, "VERIFIED") == 0) {
        // check whether 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
    
        // 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'];
        $txn_id = $_POST['txn_id'];
        $receiver_email = $_POST['receiver_email'];
        $payer_email = $_POST['payer_email'];
        $custom_encrypted_serialized_variables = $_POST['custom'];
    
        ...
        ...
    }
    

    And then proceed with variables decrypting and unserializing with common unserialize() and decrypt functions.

    Along with the other useful data you may send with the “custom” variable in the paypal checkout form, send the client’s email and you’re done!

    P.S: I know this solution is not optimal and maybe there are alternative solutions, but I found this one quick and efficient. Hints and corrections are appreciated!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two scripts that are called in one program, the first script creates
I have two scripts running on the same page, one is the jQuery.hSlides.js script
I have written two scripts where one script calls subprocess.Popen to run a terminal
i have a form that consist of two textfield and one combobox. i want
I have two jquery scripts on one page that both target on-site links via
I have two PHP scripts. One acts as a backend, and contains a class
I have two large tables and want to combine all of the column names
I have two directories that contain files. I want to combine all these files
I have two tcl scripts. I want to run the second script when the
I have two shell scripts, one that serves as the main program and another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.