paypal ipn php script unresponsive
<p>I started with the standard ipn php script paypal provides as a sample guideline and 
compared that with variations others used. I do not see why it is not succeeding
in executing the database inquiry and sending the email results out that I separately verified works stand alone.  The paypal results indicate the HTTP Response was 200 (successful?)
Whats missing?  script attached:</p>

<pre><code>&lt;?php
$connection = mysql_connect("rockymountainplan.startlogicmysql.com", "craigdavis", "********") or die ("Could not connect to server.");
$db = mysql_select_db("rockymntdb", $connection) or die ("Could not select database."); 

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key =&gt; $value) {
$value = urlencode(stripslashes($value));
$req .= "&amp;$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name1 = $_POST['item_name1'];
$item_name2 = $_POST['item_name2'];
$item_number1 = $_POST['item_number1'];
$item_number2 = $_POST['item_number2'];
$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'];
$address_name= $_POST['address_name'];

if (!$fp) {
// HTTP ERROR
} else {

fputs ($fp, $header . $req);

$res=stream_get_contents($fp, 1024);

// this method swapped out for above solution
/* while (!feof($fp)) {
   $res = fgets ($fp, 1024);  */



        if (strcmp ($res, "VERIFIED") == 0) {

        function recoverPlanID($itemName)  {
            $planNamePlusPlanID = strrchr($itemName, "-+");  // str from last occurance of needle to end:  (haystack, needle)
            $planIDPlusColon = strrchr($planNamePlusPlanID, "+floorplan");      // 
            $planNameWithSyntax = str_replace($planIDPlusColon, "", $planNamePlusPlanID ); // needle, replacmnt, haystack
            $planNameWithDash = str_replace("-+", "", $planNameWithSyntax ); // needle, replacmnt, haystack
            $planNameClean = str_replace("+", " ", $planNameWithDash ); // needle, replacmnt, haystack  
            return $planNameClean;
         }

        function getMSSName($plan_id, $connection) {
            $links = ''; 
            $sqlPlans = "SELECT plan_name, mini_study_set  FROM floorplan WHERE plan_name = '$plan_id' ";
            $resultPlans = mysql_query($sqlPlans,$connection) or die("Could not find floorplan.");

            while($row = mysql_fetch_array($resultPlans) )  {
                $plan_name =   $row["plan_name"];
                $mini_study_set =   $row["mini_study_set"];
            }
            return $mini_study_set;
        } 


        $sumLinks = '';

        if($item_number1 == 'MSS01') { 

            $sendEmail = true; 
            $planName = recoverPlanID($item_name1);
            $pdfFileName = getMSSName($planName, $connection);
            $sumLinks .= "&lt;a href='http://rockymountainplan.com/miniStudySets/$pdfFileName'&gt;$planName&lt;/a&gt;&lt;br&gt;";

        }

        if($item_number2 == 'MSS01') { 

            $sendEmail = true; 
            $planName = recoverPlanID($item_name2);
            $pdfFileName = getMSSName($planName, $connection);
            $sumLinks .= "&lt;a href='http://rockymountainplan.com/miniStudySets/$pdfFileName'&gt;$planName&lt;/a&gt;&lt;br&gt;";

        }





        if($sendEmail == 'true') {
        // send email to buyer with link to Mini Study Set PDF file
            $recipientAddr = $payer_email;
            $subject = "Link to Rocky Mnt Plan Co StudySet.pdf DOWNLOADs";
            $message = "&lt;html&gt;&lt;body&gt;$address_name,&lt;br&gt;
            The StudySet.pdf file(s) you purchased from Rocky Mountain Plan Co.&lt;br&gt; 
            can be downloaded by clicking on the following link(s):&lt;br&gt;&lt;br&gt; $sumLinks &lt;/body&gt;&lt;/html&gt;";
            $from = "3treesDrafting@comcast.net";
            $mailHeaders = "From: $from\n";
            $mailHeaders .= "MIME-Version: 1.0 \n";
            $mailHeaders .= "Content-Type: text/html; charset=us-ascii; \n\n";
            mail($recipientAddr,$subject,$message,$mailHeaders);   // mail to webmaster
        }

    }  // End of VERIFIED loop
fclose ($fp);
}
?&gt;
</code></pre>
