2016-04-11 12 views
2

クライアントが「PayPalで支払う」ボタン(以下の例では「名前=提出」)を押した後、特定の住所にメールを送信する必要があります。フォーム提出時に電子メールを送信

<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> 

私はあなたのすべてに感謝し、任意のアイデアを開いている:問題は、そのフォームが瞬時に別のページ(ペイパルウェブサイト)に私をリダイレクトしているのでを通じて取得していない電子メールを送信するために私のコードです。

あなたが直接送信ボタンにフォームを提出されています。ここでは

+0

Ajaxコードをリダイレクトカントーの前に実行され得るのだろうか? – Chilipepper

+0

はい、この場合、フォーム提出/投稿にはjavascriptも使用します。 –

答えて

2

これを試してみてください。 2つの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> 
0

はあなたが始めるために何かです。代わりに、jQueryを使用してボタンがクリックされたときに関数を実行し、フォームを送信します。

フォームにIDを指定します。

<form id="form" ... .. </form>  

$(document).ready(function(){ 
    $("#btn").click(function(){ 
     //Your email send code here... 
     alert("send your email here, then..."); 
     //submit your form 
     $("#form").submit() 
    }) 
}) 
0
Give "id" to input:submit and use jQuery to send email. 
$(document).ready(function(){ 
    $.ajax({ 
     url : "sendMail.php",`enter code here 
     type: "POST", 
     data : "YOURDATE", // "FIELDNAME1=FIELDNAME1VAL&FIELDNAME2=FIELDNAME2VAL etc 
      success: function(data, textStatus, jqXHR){ 
        alert("Mail Send"); 
      } 
    }); 
}); 

// sendMail.php`enter code here` 

$FIELDNAME1 = $_POST['FILEDNAME1']; 
---- 
--- 
$FIELDNAMEN = $_POST['FILEDNAMEN']; 

// add normal php code for sending mail 
関連する問題