带验证和 Paypal 的 PHP 联系表

标签 php html forms paypal

目标是让客户填写表格

然后点击提交将发送一封电子邮件

然后会出现一条消息

然后重定向到一个完全隐藏的简单 Paypal 支付

我无法让页面打开到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>

和 php

最佳答案

您在 HTTP header 中发送混合指令。

虽然您可以同时发送正文数据和重定向 header ,但这毫无意义,因为将遵循重定向。

但真正的问题是您在设置重定向 header (header: location....') 之前发送数据 (echo ...); -您必须在输出前发送所有 header 。

如果您真的想按此顺序回显数据,请按照此处的 hack:Interview Question: Can we have an echo before header?

关于带验证和 Paypal 的 PHP 联系表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41841646/

相关文章:

php - 如何添加、编辑和删除数据库的逗号分隔值。?

javascript - Safari 浏览器上的属性下载

javascript - 使用 load 方法发送表单后隐藏提交按钮

forms - Sencha Touch/Ext : How to disable a Form inside a Tab Panel (tabpanel) without disabling the Tab

PHP - 使用表单输入中的 id 创建一个 switch 语句

php - 在 MAC 上升级到 PHP 5.4 并删除版本 5.3.10

javascript - Angular 和 php/mysql 中的路由

php - 检查用户名和数字中的特殊字符以及名字和姓氏表单条目中的特殊字符

javascript - 输入字段为空时卡片翻转不起作用

html - 即使使用 block 链接样式,链接的 div 在 ie7 中也不起作用