简体   繁体   中英

PHP Contact Form w/ verification & Paypal

the objective is to have a customer fill a form

then hit submit to which will send an email

then a message will appear

then a redirect to a simple paypal payment which is all hidden

i cannot get the page to open to paypal

 <? php // configure $name = $_POST['name']; $from = 'contact <demo@domain.com>'; $sendTo = 'NEWCONTACT<new@gmail.com>'; $subject = 'New contact'; $fields = array('name' => 'Name', 'email' => 'Email', 'residence' => 'Residence', 'qualification' => 'Qualification', 'marital' => 'Marital', 'children' => 'Children', 'income' => 'Income', 'asset' => 'Asset', 'phone' => 'phone', 'nationality' => 'Nationality', 'interested' => 'interested', 'occupation' => 'Occupation', 'soccupation' => 'Spouse Occupation', 'SpouseEducationalQualification' => 'SpouseEducationalQualification', 'history' => 'History', 'source' => 'Source', 'comments' => 'Comments'); // array variable name => Text to appear in the email $okMessage = 'Contact form successfully submitted. Thank you '.$name. ', I will get back to you soon!'; $errorMessage = 'There was an error while submitting the form. Please try again later'; // let's do the sending try { foreach($_POST as $key => $value) { if (isset($fields[$key])) { $emailText. = "<pre>". "$fields[$key]: $value". "</pre>"; } } $headers = array('Content-Type: text/html; charset="UTF-8";', 'From: '.$from, 'Reply-To: '.$from, 'Return-Path: '.$from, ); mail($sendTo, $subject, $emailText, implode("\\n", $headers)); $responseArray = array('type' => 'success', 'message' => $okMessage); } catch (\\Exception $e) { $responseArray = array('type' => 'danger', 'message' => $errorMessage); } if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $encoded = json_encode($responseArray); header('Content-Type: application/json'); echo $encoded; } else { echo $responseArray['message']; } $query_data = array( 'amount' => '900', 'business' => 'uaetousavisa@gmail.com', 'cmd' => '_xclick', 'currency_code' => 'USD', 'item_number' => $_POST['item_number'], 'item_name' => $_POST['item_name'] ); // redirect to PayPal header('Location: https://www.paypal.com/?'.http_build_query($query_data));
 <form id="contact-form" method="post" action="contact.php" role="form"> <div class="col-md-6"> <div class="form-group"> <input class="form-control" id="form_name" name="name" type="name" placeholder="Your Full Name" required="required" data-error="Firstname is required."> <div class="help-block with-errors"></div> </div> <div class="form-group"> <input class="form-control" id="form_email" name="email" type="email" placeholder="Your email" required="required" data-error="Email is required."> <div class="help-block with-errors"></div> </div> <div class="form-group"> <input class="form-control" id="income" type="text" name="income" placeholder="Net Monthly Income"> </div> </div> <div class="col-md-12"> <button type="submit" class="btn btn-default more-get" name="buy">Submit</button> <div class="messages"></div> </form>

and the php

You are sending mixed instructions in the HTTP headers.

While you can send both body data and a redirect header, it's pretty pointless as the redirect will be followed.

But the real problem is that you are sending data ( echo ... ) before setting the redirect header ( header: location....'); - you must send all headers before output.

If you really want to echo data in this order, follow the hack here: Interview Question: Can we have an echo before header?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM