2012-10-04 16 views
0

我使用電子郵件營銷公司發送HTML電子郵件,並在帖子中使用絕對路徑幷包含用於處理表單的隱藏變量。我想添加一個驗證碼,但不知道如何去做。所有的php captcha選項都會使用該帖子發佈到process.php頁面。我該怎麼做,並且仍然絕對地發佈給電子郵件營銷公司,包括隱藏變量?PHP表單:使用驗證碼發佈到絕對路徑

+0

鈣我們跟「絕對路徑」假設你的意思網址? – arkascha

+0

是的,網址無誤。 – wgoodman

回答

0

如果我理解正確,你現在只需設置窗體的action屬性的營銷公司的網址:

<form action="http://marketingsite.com/form.php" method="post"> 

......但現在,你需要在發送之前驗證數據。

一種方法是在您自己的網站process.php內驗證您的數據,然後使用cURL將數據發佈到市場營銷網站。當你安裝PHP

http://php.net/manual/en/book.curl.php

cURL通常包括在內。它用於讀取數據並將數據發送給其他人的網頁。您可以選擇要發佈的數據,然後使用cURL發佈。

<?php 
// validate the CAPTCHA code first 

// This array will hold the data that you are POSTing to the marketing site 
$post = array(); 

// validate the other fields here, and add the relevant ones to an array. e.g.: 
if(strlen($_POST['name']) > 4 && strlen($_POST['name'] < 20)) { 
    $post['name'] = $_POST['name']; 
} 
if(strlen($_POST['hiddenfield'] != 0)) { 
    $post['hiddenfield'] = $_POST['hiddenfield']; 
} 
// ... 

$curl = curl_init(); 

// post the data to this url: 
curl_setopt($curl,CURLOPT_URL,'http://marketingsite.com/form.php'); 

// This indicates that we are going to post some data: 
curl_setopt($curl,CURLOPT_POST,true); 

// Post this data: 
curl_setopt($curl,CURLOPT_POSTFIELDS,$post); 

// If your script successfully sent the data, && if http://marketingsite.com/form.php returned a 200 code 
//  (i.e.: not a 404 error or something) 
if(curl_exec($curl) && curl_getinfo($curl,CURLINFO_HTTP_CODE) == 200) { 
    echo 'Thank you for submitting your data'; 
} else { 
    echo 'Your data was not submitted :('; 
} 
curl_close($curl); 
?> 

這會發布您選擇的所有內容,包括您要添加的隱藏字段或其他字段。

您還可以設置其他選項。您可以嘗試閱讀接收網頁並將該內容回傳到您的網站上。您可以瞭解更多關於cURLPHP這裏:

http://php.net/manual/en/book.curl.php

+0

謝謝你的迴應。我會嘗試。 – wgoodman