Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PHP mailer正在发送,但是一些代码在发送后没有呈现_Javascript_Php_Email_Stripe Payments - Fatal编程技术网

Javascript PHP mailer正在发送,但是一些代码在发送后没有呈现

Javascript PHP mailer正在发送,但是一些代码在发送后没有呈现,javascript,php,email,stripe-payments,Javascript,Php,Email,Stripe Payments,我不确定用什么方式来表达这个标题。我的问题涉及这个函数mail($to、$subject、$message、$headers)它运行在PHP文件的中间,它从表单中获取信息,创建带有条纹API的令牌,然后用条纹收取该卡。 Stripe仍然会接收数据,并通过包含邮件功能正确地向卡收费,但是页面不像以前那样显示成功消息,几乎任何东西都会在购买后显示标题,通常情况下,表单会清除并显示成功消息。邮件功能没有包含在成功的表单提交中之后,这就像任何事情一样 我大部分时间都花在javascript上,所以这可能

我不确定用什么方式来表达这个标题。我的问题涉及这个函数
mail($to、$subject、$message、$headers)它运行在PHP文件的中间,它从表单中获取信息,创建带有条纹API的令牌,然后用条纹收取该卡。
Stripe仍然会接收数据,并通过包含邮件功能正确地向卡收费,但是页面不像以前那样显示成功消息,几乎任何东西都会在购买后显示标题,通常情况下,表单会清除并显示成功消息。邮件功能没有包含在成功的表单提交中之后,这就像任何事情一样

我大部分时间都花在javascript上,所以这可能完全是因为我对PHP不熟悉

下面是完整的代码

<?php include 'head.php'; ?>
<body>

  <!--header-->
  <?php include 'header.php'; ?>


  <!--header-->

  <script type="text/javascript">
  // $('input.quantity').keyup(function(){
  //     var value = $( this ).val();
  //     var bookQuantity = $( "input.bfh-number" ).text( value );
  //     console.log(bookQuantity);
  // })




  $(document).ready(function() {


    $( ".quantity" )
  .keyup(function() {
    var value = $( this ).val();
    console.log(value);
    subTotal = 150 * value;
    $( '.paymentTotal' ).text( '$' + subTotal );
  }).keyup();


    $('#payment-form').bootstrapValidator({
      message: 'This value is not valid',
      feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
      },
      submitHandler: function(validator, form, submitButton) {
        var chargeAmount = 3000; //amount you want to charge, in cents. 1000 = $10.00, 2000 = $20.00 ...
        // createToken returns immediately - the supplied callback submits the form if there are no errors
        Stripe.createToken({
          number: $('.card-number').val(),
          cvc: $('.card-cvc').val(),
          exp_month: $('.card-expiry-month').val(),
          exp_year: $('.card-expiry-year').val(),
          name: $('.card-holder-name').val(),
          address_line1: $('.address').val(),
          address_city: $('.city').val(),
          address_zip: $('.zip').val(),
          address_state: $('.state').val(),
          quantity: $('.quantity').val(),
          address_country: $('.country').val()
        }, chargeAmount, stripeResponseHandler);
        return false; // submit from callback
      },
      fields: {
        street: {
          validators: {
            notEmpty: {
              message: 'The street is required and cannot be empty'
            },
            stringLength: {
              min: 6,
              max: 96,
              message: 'The street must be more than 6 and less than 96 characters long'
            }
          }
        },
        city: {
          validators: {
            notEmpty: {
              message: 'The city is required and cannot be empty'
            }
          }
        },
        zip: {
          validators: {
            notEmpty: {
              message: 'The zip is required and cannot be empty'
            },
            stringLength: {
              min: 3,
              max: 9,
              message: 'The zip must be more than 3 and less than 9 characters long'
            }
          }
        },
        email: {
          validators: {
            notEmpty: {
              message: 'The email address is required and cannot be empty'
            },
            emailAddress: {
              message: 'The input is not a valid email address'
            },
            stringLength: {
              min: 6,
              max: 65,
              message: 'The email must be more than 6 and less than 65 characters long'
            }
          }
        },
        cardholdername: {
          validators: {
            notEmpty: {
              message: 'The card holder name is required and cannot be empty'
            },
            stringLength: {
              min: 6,
              max: 70,
              message: 'The card holder name must be more than 6 and less than 70 characters long'
            }
          }
        },
        first_name: {
          validators: {
            notEmpty: {
              message: 'The card holder name is required and cannot be empty'
            }
          }
        },
        cardnumber: {
          selector: '#cardnumber',
          validators: {
            notEmpty: {
              message: 'The credit card number is required and cannot be empty'
            },
            creditCard: {
              message: 'The credit card number is invalid'
            },
          }
        },
        expMonth: {
          selector: '[data-stripe="exp-month"]',
          validators: {
            notEmpty: {
              message: 'The expiration month is required'
            },
            digits: {
              message: 'The expiration month can contain digits only'
            },
            callback: {
              message: 'Expired',
              callback: function(value, validator) {
                value = parseInt(value, 10);
                var year         = validator.getFieldElements('expYear').val(),
                currentMonth = new Date().getMonth() + 1,
                currentYear  = new Date().getFullYear();
                if (value < 0 || value > 12) {
                  return false;
                }
                if (year == '') {
                  return true;
                }
                year = parseInt(year, 10);
                if (year > currentYear || (year == currentYear && value > currentMonth)) {
                  validator.updateStatus('expYear', 'VALID');
                  return true;
                } else {
                  return false;
                }
              }
            }
          }
        },
        expYear: {
          selector: '[data-stripe="exp-year"]',
          validators: {
            notEmpty: {
              message: 'The expiration year is required'
            },
            digits: {
              message: 'The expiration year can contain digits only'
            },
            callback: {
              message: 'Expired',
              callback: function(value, validator) {
                value = parseInt(value, 10);
                var month        = validator.getFieldElements('expMonth').val(),
                currentMonth = new Date().getMonth() + 1,
                currentYear  = new Date().getFullYear();
                if (value < currentYear || value > currentYear + 100) {
                  return false;
                }
                if (month == '') {
                  return false;
                }
                month = parseInt(month, 10);
                if (value > currentYear || (value == currentYear && month > currentMonth)) {
                  validator.updateStatus('expMonth', 'VALID');
                  return true;
                } else {
                  return false;
                }
              }
            }
          }
        },
        cvv: {
          selector: '#cvv',
          validators: {
            notEmpty: {
              message: 'The cvv is required and cannot be empty'
            },
            cvv: {
              message: 'The value is not a valid CVV',
              creditCardField: 'cardnumber'
            }
          }
        },
      }
    });
  });
</script>
<script type="text/javascript">
  // this identifies your website in the createToken call below
  //Stripe.setPublishableKey('pk_live_random');
  Stripe.setPublishableKey('pk_test_random');



  function stripeResponseHandler(status, response) {
    if (response.error) {
      // re-enable the submit button
      $('.submit-button').removeAttr("disabled");
      // show hidden div
      document.getElementById('a_x200').style.display = 'block';
      // show the errors on the form
      $(".payment-errors").html(response.error.message);
    } else {
      var form$ = $("#payment-form");
      // token contains id, last4, and card type
      var token = response['id'];
      // insert the token into the form so it gets submitted to the server
      form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
      // and submit
      form$.get(0).submit();
    }
  }

</script>

<!--content-->

<div class="global indent">
  <div class="container partner-wrap">
    <form action="" method="POST" id="payment-form" class="form-horizontal">
      <div class="row"> <div class="col-lg-6"><img id="buyImage" src="img/book.jpg" /></div>
        <div class="col-lg-6"><h2>The Economic Definition of Ore</h2><p>Price:$150</p>
          <label class="control-label" for="textinput">Quantity</label>
          <div class="form-group col-sm-4">
            <div class="col-lg-12">
            <h4>Quantity</h4>
            </div>
            <div class="col-lg-12">
            <input type="text" name="quantity" value="1" data-buttons="false" class="quantity form-control bfh-number">
            </div>
          </div>

          <div class="col-sm-8">
          <h4 class="subTotalRight borderBottom">Total:</h4>
          <h5 class="paymentTotal subTotalRight"></h5>
          </div>
        </div>

  </div>




    <div class="row row-centered">
      <div class="col-md-12">
        <div class="page-header">
          <h2 class="gdfg">Secure Payment Form</h2>
        </div>
        <noscript>
          <div class="bs-callout bs-callout-danger">
            <h4>JavaScript is not enabled!</h4>
            <p>This payment form requires your browser to have JavaScript enabled. Please activate JavaScript and reload this page. Check <a href="http://enable-javascript.com" target="_blank">enable-javascript.com</a> for more informations.</p>
          </div>
        </noscript>
        <?php

        $error = '';
        $success = '';

        require 'Stripe.php';

        if ($_POST) {

          $token = $_POST['stripeToken'];
          $email = $_POST["email"];
          $quantity = $_POST["quantity"];
          $firstName = $_POST["firstName"];
          $lastName = $_POST["lastName"];


          // Get the values from the $_POST array:
         $price = 15000;




        $total = $price * $quantity;
        $customertotal = $price * $quantity / 100;



          //Stripe::setApiKey("sk_random");
          Stripe::setApiKey("sk_random");

          $error = '';
          $success = '';





          try {

            $customer = Stripe_Customer::create(array(
            'email' => $email,
            'card'  => $token,
            "description" => $quantity . " copies of The Economic Definition of Ore -Cut-off Grades in Theory and Practice"
            ));

            $charge = Stripe_Charge::create(array(
            "amount" => $total, // amount in cents, again
            "currency" => "cad",
            'customer' => $customer->id,
            "metadata" => array("First Name:" => $firstName, "Last Name:" => $lastName)

            )
            );

            $success = '<div class="alert alert-success">
              <strong>Success!</strong> Your payment was successful. For $' . $customertotal . ', and you have ordered ' . $quantity . ' copies </div>';



              $to  = $email; // note the comma

              // subject
              $subject = 'Economic Definition of Ore Purchase';

              // message
              $message = '
              <html>
              <head>
                <title>Sumary of Purchase</title>
              </head>
              <body>
                <table>
                  <tr>
                    <td> Hi ' . $firstName . '</td>
                  </tr>
                  <tr>
                    <td>
                      <p>Here is a summary of your recent purchase.</p>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <p>Your total purchase is $'.$customertotal . ' </p>
                      <p>The number of books you have ordered is <b>'  . $quantity . '</b> </p>
                    </td>
                  </tr>

                </table>
              </body>
              </html>
              ';

              // To send HTML mail, the Content-type header must be set
              $headers  = 'MIME-Version: 1.0' . "\r\n";
              $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

              // Additional headers
              $headers .= 'To: '. $firstName .' <' . $email . ' >  ' . "\r\n";
              $headers .= 'From: Comet <info@cometstrategy.com>' . "\r\n";
              // $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

              // Mail it
              mail($to, $subject, $message, $headers);



          }
          catch (Exception $e) {
            $error = '<div class="alert alert-danger">
              <strong></strong> '.$e->getMessage().'
            </div>';
          }
        }
        ?>
        <span class="payment-success">
          <?= $success ?>
          <?= $error ?>

        </span>

        <div class="alert alert-danger" id="a_x200" style="display: none;"> <strong></strong> Please fill out all required fields. </div>




          <!-- Street -->

          <div class="row">
            <div class="col-md-6">

              <!-- Form Name -->
              <legend>Billing Details</legend>


              <fieldset>


          <!-- Street -->
          <div class="form-group">
            <label class="col-sm-4 control-label" for="textinput">First Name</label>
            <div class="col-sm-12">
              <input type="text" name="firstName" placeholder="First Name" class="firstName form-control">
            </div>
          </div>

          <!-- Street -->
          <div class="form-group">
            <label class="col-sm-4 control-label" for="textinput">Last Name</label>
            <div class="col-sm-12">
              <input type="text" name="lastName" placeholder="Last Name" class="firstName form-control">
            </div>
          </div>



          <!-- Street -->
          <div class="form-group">
            <label class="col-sm-4 control-label" for="textinput">Street</label>
            <div class="col-sm-12">
              <input type="text" name="street" placeholder="Billing Address" class="address form-control">
            </div>
          </div>

          <!-- City -->
          <div class="form-group">
            <label class="col-sm-4 control-label" for="textinput">City</label>
            <div class="col-sm-12">
              <input type="text" name="city" placeholder="City" class="city form-control">
            </div>
          </div>

          <!-- State -->
          <div class="form-group">
            <label class="col-sm-4 control-label" for="textinput">State</label>
            <div class="col-sm-12">
              <input type="text" name="state" maxlength="65" placeholder="State" class="state form-control">
            </div>
          </div>

          <!-- Postcal Code -->
          <div class="form-group">
            <label class="col-sm-4 control-label" for="textinput">Postal Code</label>
            <div class="col-sm-12">
              <input type="text" name="zip" maxlength="9" placeholder="Postal Code" class="zip form-control">
            </div>
          </div>

          <!-- Country -->
          <div class="form-group">
            <label class="col-sm-4 control-label" for="textinput">Country</label>
            <div class="col-sm-12">
              <!--input type="text" name="country" placeholder="Country" class="country form-control"-->
              <!-- <div class="country bfh-selectbox bfh-countries" name="country" placeholder="Select Country" data-flags="true" data-filter="true"> </div> -->
              <select class="form-control bfh-countries" data-country="AU"></select>
              <!-- <div class="bfh-selectbox bfh-countries" data-country="AU" data-flags="true"> -->
              <!-- </div> -->
            </div>
          </div>

          <!-- Email -->
          <div class="form-group">
            <label class="col-sm-4 control-label" for="textinput">Email</label>
            <div class="col-sm-12">
              <input type="text" name="email" maxlength="65" placeholder="Email" class="email form-control">
            </div>
          </div>


        </div>

        <div class="col-md-6">


          <fieldset>
            <legend>Card Details</legend>

            <!-- Card Holder Name -->
            <div class="form-group">
              <label class="col-sm-4 control-label"  for="textinput">Card Holder's Name</label>
              <div class="col-sm-12">
                <input type="text" name="cardholdername" maxlength="70" placeholder="Card Holder Name" class="card-holder-name form-control">
              </div>
            </div>

            <!-- Card Number -->
            <div class="form-group">
              <label class="col-sm-4 control-label" for="textinput">Card Number</label>
              <div class="col-sm-12">
                <input type="text" id="cardnumber" maxlength="19" placeholder="Card Number" class="card-number form-control">
              </div>
            </div>

            <!-- Expiry-->
            <div class="form-group">
              <label class="col-xs-12 col-sm-12 control-label" for="textinput">Card Expiry Date</label>
              <div class="col-sm-12">
                <div class="form-inline">
                  <select name="select2" data-stripe="exp-month" class="card-expiry-month stripe-sensitive required form-control">
                    <option value="01" selected="selected">01</option>
                    <option value="02">02</option>
                    <option value="03">03</option>
                    <option value="04">04</option>
                    <option value="05">05</option>
                    <option value="06">06</option>
                    <option value="07">07</option>
                    <option value="08">08</option>
                    <option value="09">09</option>
                    <option value="10">10</option>
                    <option value="11">11</option>
                    <option value="12">12</option>
                  </select>
                  <span> / </span>
                  <select name="select2" data-stripe="exp-year" class="card-expiry-year stripe-sensitive required form-control">
                  </select>
                  <script type="text/javascript">
                    var select = $(".card-expiry-year"),
                    year = new Date().getFullYear();

                    for (var i = 0; i < 12; i++) {
                      select.append($("<option value='"+(i + year)+"' "+(i === 0 ? "selected" : "")+">"+(i + year)+"</option>"))
                    }
                  </script>
                </div>
              </div>
            </div>

            <!-- CVV -->
            <div class="form-group">
              <label class="col-sm-4 control-label" for="textinput">CVV/CVV2</label>
              <div class="col-sm-4">
                <input type="text" id="cvv" placeholder="CVV" maxlength="4" class="card-cvc form-control">
              </div>

            </div>
            <hr>
            <div class="row">
            <div class="col-sm-12">
              <h3>Total ($USD)</h3>
            </div>
            <div class="col-sm-12">
            <h4 class="paymentTotal"></h4>
            </div>

            <div class="col-sm-12">
              <button class="btn btn-success" type="submit">Pay Now</button>
            </div>

          </div>
            <!-- Important notice -->
            <!-- <div class="form-group"> -->
              <!-- <div class="panel panel-success"> -->
              <!-- <div class="panel-heading">
              <h3 class="panel-title">Important notice</h3>
            </div>
            <div class="panel-body">
            <p>Your card will be charged 30€ after submit.</p>
            <p>Your account statement will show the following booking text:
            XXXXXXX </p>
          </div>
        </div> -->


      </fieldset>
    </div>
  </div>
    </form>

  </div>
</div>


  </div>
</div>

    <!--footer-->
    <?php include 'footer.php'; ?>

    <script src="js/bootstrap.min.js"></script>
    <script src="js/tm-scripts.js"></script>
  </body>
  </html>

//$('input.quantity').keyup(函数(){
//var值=$(this.val();
//var bookQuantity=$(“input.bfh number”).text(值);
//控制台日志(账面数量);
// })
$(文档).ready(函数(){
$(“数量”)
.keyup(函数(){
var值=$(this.val();
console.log(值);
小计=150*值;
$('.paymentTotal')。文本('$'+小计);
}).keyup();
美元(“#付款单”)。bootstrapValidator({
消息:“此值无效”,
反馈图标:{
有效:“glyphicon glyphicon ok”,
无效:“glyphicon glyphicon删除”,
正在验证:“glyphicon glyphicon刷新”
},
submitHandler:函数(验证器、表单、submitButton){
var chargeAmount=3000;//您要收取的金额,单位为美分。1000=$10.00,2000=$20.00。。。
//createToken立即返回-如果没有错误,提供的回调将提交表单
Stripe.createToken({
编号:$('.card number').val(),
cvc:$('.card cvc').val(),
exp_month:$('.card expiration month').val(),
exp_year:$(“.卡到期年”).val(),
名称:$('.card holder name').val(),
地址第1行:$('.address').val(),
地址城市:$('.city').val(),
地址:$('.zip').val(),
地址\状态:$('.state').val(),
数量:$('.quantity').val(),
地址_country:$('.country').val()
}、费用金额、剥离响应处理程序);
返回false;//从回调提交
},
字段:{
街道:{
验证器:{
注意:{
消息:“街道是必需的,不能为空”
},
弦长:{
民:6,,
最高:96,
信息:“街道长度必须超过6个字符且小于96个字符”
}
}
},
城市:{
验证器:{
注意:{
消息:“城市是必需的,不能为空”
}
}
},
邮编:{
验证器:{
注意:{
消息:“zip是必需的,不能为空”
},
弦长:{
民:3,,
最高:9,
消息:“zip长度必须大于3个字符,小于9个字符”
}
}
},
电邮:{
验证器:{
注意:{
消息:“电子邮件地址是必需的,不能为空”
},
电子邮件地址:{
消息:“输入不是有效的电子邮件地址”
},
弦长:{
民:6,,
最高:65,
消息:“电子邮件长度必须超过6个字符且少于65个字符”
}
}
},
持卡人姓名:{
验证器:{
注意:{
消息:“持卡人姓名为必填项,不能为空”
},
弦长:{
民:6,,
最高:70,
信息:“持卡人姓名长度必须超过6个字符且少于70个字符”
}
}
},
姓名:{
验证器:{
注意:{
消息:“持卡人姓名为必填项,不能为空”
}
}
},
卡号:{
选择器:“#卡号”,
验证器:{
注意:{
消息:“信用卡号是必需的,不能为空”
},
信用卡:{
消息:“信用卡号无效”
},
}
},
每月:{
选择器:“[data stripe=“exp month”]”,
验证器:{
注意:{
消息:“到期月份是必需的”
},
数字:{
消息:“到期月份只能包含数字”
},
回拨:{
消息:“过期”,
回调:函数(值、验证器){
value=parseInt(值,10);
var year=validator.getFieldElements('expYear').val(),
currentMonth=新日期().getMonth()+1,
currentYear=新日期().getFullYear();
如果(值<0 | |值>12){
返回false;
}
如果(年份=“”){
返回true;
}
年份=parseInt(年份,10);
如果(年>当前年| |(年==当前年和值>当前月)){
validator.updateStatus('expYear','VALID');
返回true;
}否则{
返回false;
}
}
}
}
},
年份:{
选择器:“[data stripe=“exp year”]”,
验证器:{
注意: