我目前正在使用此代码将表单的数据发布到https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx:
<script type="text/javascript">
$(document).ready(function(){
$("#textnextofkin").validate({
debug: false,
rules: {
name: "required",
email: {
required: true,
email: true
}
},
messages: {
name: "Please let us know who you are.",
email: "",
},
submitHandler: function(form) {
// do other stuff for a valid form
$.post('http://www.example.co.uk/erc/process2.php', $("#textnextofkin").serialize(), function(data) {
$('#results').html(data);
});
}
});
});
</script>
<form name="textnextofkin" id="textnextofkin" method="POST" action="">
<div class="hiddenfields">
<p>Username:<br>
<input name="EsendexUsername" type="text" value="AAAAA"></p>
<p>Password:<br>
<input name="EsendexPassword" type="password" value="AAAAA"></p>
<p>Account:<br>
<input name="EsendexAccount" type="text" value="AAAAA"></p>
<p>Send Name<br>
<input name="EsendexOriginator" type="text" value="example"></p>
<p>Recipient:<br>
<input name="EsendexRecipient" type="text" value="01234123456"></p>
<p>Message:<br>
<input name="EsendexBody" rows="3" cols="20" value="Hello test message"></p></div>
<input type="submit" class="email-buttons" name="submit" value="Text next of kin">
</form>
process2.php:
<?php
// Initialise CURL
$curl_handle = curl_init();
$data ="EsendexUsername=AAAAA&EsendexPassword=AAAAA&EsendexAccount=AAAAA&EsendexRecipient=01234123456&EsendexBody=test";
$url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
curl_setopt ($curl_handle, CURLOPT_URL,$url);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);
$result = curl_exec ($curl_handle);
curl_close ($curl_handle);
?>
我需要更改它,以便我可以将表单数据发送到process.php,然后使用process.php将信息发送到Esendex网站。我需要这样做,因为process.php包含我需要包含在表单中的数据(例如$ _SESSION ['first_name'])。我想我需要将上面的Esendex URL更改为process.php,但后来我不知道要在process.php页面输入什么来发送它收到的信息。
有人可以帮我这样做吗?
感谢您的帮助
答案 0 :(得分:1)
您使用ajax将所有内容发布到process.php。在那里你从$ _POST数组中获取所有变量并追加你的字段。
然后你可以使用curl重新发布到esendex并捕获结果,然后返回。
答案 1 :(得分:1)
您需要知道的最重要的是,在使用下面的代码之前,您需要启用curl。 Curl通常是启用的,但值得检查
<?php
// Initialise CURL
$curl_handle = curl_init();
$data ="EsendexUsername=value&EsendexUsername=value&EsendexAccount=value";
$url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
curl_setopt ($curl_handle, CURLOPT_URL,$url);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);
$result = curl_exec ($curl_handle);
curl_close ($curl_handle);
?>
修改强>
尝试使用此代码
<?php
// Initialise CURL
$curl_handle = curl_init();
$data ="EsendexUsername=value&EsendexUsername=value&EsendexAccount=value";
$url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
curl_setopt ($curl_handle, CURLOPT_URL,$url);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);
curl_setopt( $curl_handle, CURLOPT_SSL_VERIFYPEER, false ); //so we can post to https
$result = curl_exec ($curl_handle);
curl_close ($curl_handle);
?>
上面的代码只是一个片段,所以我没有传递所有的$ data,因此你必须让它更完整。将代码放在process.php中,它应该将数据发送到Esendex网站。
修改强> 我建议您阅读CURL以真正了解上述代码中的内容。一个很好的起点是php.ne t网站