in reply to PayPal IPN Script End of script output before headers:

Is that really all that the server log says? What is the output when you run the script from the command line? See also CGI Help Guide and Troubleshooting Perl CGI scripts. Perhaps try adding use CGI::Carp qw/fatalsToBrowser/; to the top of your script (for debugging only!).

Replies are listed 'Best First'.
Re^2: PayPal IPN Script End of script output before headers:
by *alexandre* (Scribe) on Nov 27, 2019 at 12:24 UTC

      "Argument "Erreur http" isn't numeric in addition (+) at /usr/lib/cgi-bin/ipn.pl line 74.: /usr/lib/cgi-bin/ipn.pl"

      Line 74 of what you posted doesn't seem to be line 74 of what you are running to produce this error...

        Hi, I updated my script, but now some of the variables are not accessible like item_number here is the code
        #!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Carp 'fatalsToBrowser'; use LWP::UserAgent; use Email::Sender::Simple qw(sendmail); use Email::Sender::Transport::SMTPS (); use Email::Simple (); use Email::Simple::Creator (); my $smtpserver = 'smtp.gmail.com'; my $smtpport = '587'; my $smtpuser = 'alexjaquet@gmail.com'; my $smtppassword = ''; my $transport = Email::Sender::Transport::SMTPS->new({ host => $smtpserver, port => $smtpport, ssl => "starttls", sasl_username => $smtpuser, sasl_password => $smtppassword, }); my $q = CGI->new(); my $query = 'cmd=_notify-validate;'.$q->query_string; $query =~ s/;/&/g; my $PP_server = 'ipnpb.sandbox.paypal.com'; # sandbox IP:173.0.82.66 my $url = 'https://'.$PP_server.'/cgi-bin/webscr'; my $ua = LWP::UserAgent->new( ssl_opts => { keep_alive => 1, verify_hostname => 1, SSL_version => 'SSLv23:!TLSv12', } ); my $req = HTTP::Request->new('POST',$url); $req->content_type('application/x-www-form-urlencoded'); $req->header(Host => $PP_server); $req->content($query); my $msg; my $res = $ua->request($req); # make the variable hash my %variable = map { split(m'='x, $_, 2) } grep { m'='x } split(m'&'x, $query); # assign posted variables to local variables my $item_name = $variable{'item_name_1'}; my $item_number = $variable{'item_number'}; my $item_number_1 = $variable{'item_number_1'}; my $payment_status = $variable{'payment_status'}; my $payment_amount = $variable{'mc_gross'}; my $payment_currency = $variable{'mc_currency'}; my $txn_id = $variable{'txn_id'}; my $receiver_email = $variable{'receiver_email'}; my $payer_email = $variable{'payer_email'}; if ($res->is_success) { $msg = "SUCCESS : ".$res->decoded_content; if ($res->decoded_content eq 'VERIFIED') { my $email = Email::Simple->create( header => [ To => 'alexjaquet@gmail.com', From => 'robot@avant-garde.info', Subject => "Payement recu d une publicite p +ar :".$payer_email , ], body => $msg." TX ID : ".$txn_id. " ITEM NUMBER : ".$item +_number . " ITEM NUMBER_1 : ".$item_number_1 ."RECEIVER_EMAIL : ".$r +eceiver_email,); sendmail($email, { transport => $transport }); } } else { $msg = "ERROR : ".$res->status_line; my $email = Email::Simple->create( header => [ To => 'alexjaquet@gmail.com', From => 'robot@avant-garde.info', Subject => 'Erreur dans le payement d une p +ublicite', ], body => $msg,); sendmail($email, { transport => $transport }); }
        My html page looks like the Following
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w +3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Supermarket</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> <link href="/css/main.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="conteneur"> <br /> <br/> <div class="centre"> <br/> <form method='POST' action='https://www.sandbox.paypal.com/cgi-bin +/webscr'> <input type='hidden' name='cmd' value='_cart'> <input type='hidden' name='upload' value='1'> <input type='hidden' name='business' value='alexjaquet@gmail.com'> <input type='hidden' name='bn' value='OnlineStore_Cart_WPS'> <input type='hidden' name='lc' value='CH'> <input type='hidden' name='currency_code' value='CHF'> <input type='hidden' name='no_note' value='1'> <input type='hidden' name='no_shipping' value='2'> <input type='hidden' name='quantity_1' value='1'> <input type='hidden' name='item_number_1' value='$ARTICLE{'id_article' +}'> <input type='hidden' name='item_name_1' value='$ARTICLE{'name'}'> <input type='hidden' name='amount_1' value='50.00'> <input type="hidden" name='notify_url' value='http://avant-garde.info/ +cgi-bin/ipn.pl'> <input type='submit' style='font-family:Arial;' value='Secure Order Fo +rm' name='submit3'> </form> </td></tr></table></BODY> </HTML>
        And my email response is the Following : SUCCESS : VERIFIED TX ID : 4AJ83296LX592004J ITEM NUMBER : ITEM NUMBER_1 : RECEIVER_EMAIL : alexjaquet%40gmail.com

      These two warnings sound like perhaps you've accidentally used the + operator instead of the concatenation operator ., but as marto said, you didn't actually show the code that's causing the error. As for why it's giving you a "500 Can't connect to ipnpb.sandbox.paypal.com:443", I'd suggest trying to connect to that URL using curl and writing a simple command-line script using LWP::UserAgent to connect to that server, and debugging that.

      Using the test script below I get the INVALID response (as I would expect).

      c:\inetpub\wwwroot\test>perl ipn_test.cgi
      Content-Type: text/plain
      
      REQUEST
      POST https://ipnpb.sandbox.paypal.com/cgi-bin/webscr
      Host: ipnpb.sandbox.paypal.com
      User-Agent: libwww-perl/6.38
      Content-Type: application/x-www-form-urlencoded
      
      cmd=_notify-validate&
      
      RESPONSE
      SUCCESS : INVALID
      
      #!/usr/bin/perl # ipn_test.cgi use strict; use warnings; use CGI; use CGI::Carp 'fatalsToBrowser'; use LWP::UserAgent; my $q = CGI->new(); my $query = 'cmd=_notify-validate;'.$q->query_string; $query =~ s/;/&/g; my $PP_server = 'ipnpb.sandbox.paypal.com'; # sandbox IP:173.0.82.66 my $url = 'https://'.$PP_server.'/cgi-bin/webscr'; my $ua = LWP::UserAgent->new( ssl_opts => { keep_alive => 1, verify_hostname => 1, SSL_version => 'SSLv23:!TLSv12', } ); my $req = HTTP::Request->new('POST',$url); $req->content_type('application/x-www-form-urlencoded'); $req->header(Host => $PP_server); $req->content($query); my $msg; my $res = $ua->request($req); if ($res->is_success) { $msg = "SUCCESS : ".$res->decoded_content; } else { $msg = "ERROR : ".$res->status_line; } print "Content-Type: text/plain\n\n"; printf "REQUEST\n%s\n",$req->as_string; printf "RESPONSE\n%s\n",$msg;

      If you want to run as a cgi you can use this html form to provide parameters

      <html> <head></head> <body><h1>Paypal IPN Test</h1> <form action="ipn_test.cgi" method="post"> item_name : <input type="text" name="item_name" value="f1"/><br/> item_number : <input type="text" name="item_number" value="f2"/><br/> payment_status : <input type="text" name="payment_status" value="f3"/> +<br/> mc_gross : <input type="text" name="mc_gross" value="f4"/><br/> mc_currency : <input type="text" name="mc_currency" value="f5"/><br/> txn_id : <input type="text" name="txn_id" value="f6"/><br/> receiver_email : <input type="text" name="receiver_email" value="f7"/> +<br/> payer_email : <input type="text" name="payer_email" value="f8"/><br/> <input type=submit value="submit form"> </form> </body> </html>
      HTH
      poj