客户按下“使用Paypal付款”按钮(在下面的示例中为name = submit)后,我需要向特定地址发送电子邮件。问题在于表单立即将我重定向到另一个页面(贝宝网站),因此我发送电子邮件的代码无法通过:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="business" value="[email protected]">
        <input type="hidden" name="item_name" value="Lunch Run ONLINE ORDER">
        <input type="hidden" name="amount" value="<PASS-THRU-CODE-HERE>">
        <input type="hidden" name="no_shipping" value="1">
        <input type="hidden" name="no_note" value="1">
        <input type="hidden" name="currency_code" value="USD">
        <input type="hidden" name="lc" value="US">
        <input type=hidden name="return" value="http://www.xxxxx.com/order-confirmation.html">
        <input type="hidden" name="bn" value="PP-BuyNowBF">
        <input type="image" src="img/paypal.png" border="0" name="submit" alt="Make payments with any major credit card!">
</form>


我愿意接受任何想法,谢谢大家。

最佳答案

尝试这个。您需要进行两次ajax调用。

<form id="clickonpaypalbutton">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="business" value="[email protected]">
        <input type="hidden" name="item_name" value="Lunch Run ONLINE ORDER">
        <input type="hidden" name="amount" value="<PASS-THRU-CODE-HERE>">
        <input type="hidden" name="no_shipping" value="1">
        <input type="hidden" name="no_note" value="1">
        <input type="hidden" name="currency_code" value="USD">
        <input type="hidden" name="lc" value="US">
        <input type=hidden name="return" value="http://www.xxxxx.com/order-confirmation.html">
        <input type="hidden" name="bn" value="PP-BuyNowBF">
        <input type="image" src="img/paypal.png" border="0" name="submit" alt="Make payments with any major credit card!">
</form>



<script>
$('#clickonpaypalbutton').submit(function(event) {
    if(confirm('Confirm?' )) {
        event.preventDefault();
                $.ajax({
                        type: 'POST',
                        url: 'https://www.paypal.com/cgi-bin/webscr',
                        data: $(this).serialize(),
                        success: function (data) {
                            console.log(data);
                        }
                });

                $.ajax({
                        type: 'POST',
                        url: 'path-to-your-email-sending-script',
                        data: $(this).serialize(),
                        success: function (data) {
                            console.log(data);
                        }
                });
    } else {
        event.preventDefault();
        return false;
    }
});
</script>

关于php - 在表单提交中发送电子邮件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36546939/

10-13 02:28