将php变量从一台服务器传输到另一台服务器

将php变量从一台服务器传输到另一台服务器,php,Php,我有一个联系人表单,它将输入发布到服务器中的.php文件中 部分代码: $name_field = $_POST['name']; $email_field = $_POST['email']; $phone_field = $_POST['phone']; $message_field = $_POST['message']; 在我的服务器中,我无法使用php mail(),因此我想将此变量传输到位于其他域中的另一个.php文件 我知道我可以直接在表格里做 action="http://ot

我有一个联系人表单,它将输入发布到服务器中的.php文件中
部分代码:

$name_field = $_POST['name'];
$email_field = $_POST['email'];
$phone_field = $_POST['phone'];
$message_field = $_POST['message'];
在我的服务器中,我无法使用php mail(),因此我想将此变量传输到位于其他域中的另一个.php文件

我知道我可以直接在表格里做

action="http://otherdomain.com/contact.php"
但是我希望php脚本在我的服务器上,“幕后”传输变量。
我的第一个问题是,是否可以这样做?第二,如何…

您可以使用
file\u get\u contents()
发送post请求(例如):


您将需要使用CURL

$url = 'http://www.otherdomain.com/contact.php';
$fields_string = http_build_query($_POST);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($_POST));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
echo$server\u output=curl\u exec($s); 卷曲关闭($s)

phpcontact.php

如果(isset($link)){

$sql=“在联系人(contactname、contactemail、contactsubject、contactmessage)中插入值(“$Name”、“$Email”、“$Subject”、“$Message”)”;
$res=mysqli_query($link,$sql);

您可以始终在自己的服务器上将该操作设置为php页面,然后从该页面传递到其他域。是的,这就是我想要的。如何执行此操作?
fsockopen()
谢谢,但是由于某种原因表单输入是空的。我如何检查问题出在哪里?收到的电子邮件是空的使用
CURLOPT有什么好处?禁止重用
$url = 'http://www.otherdomain.com/contact.php';
$fields_string = http_build_query($_POST);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($_POST));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
    *Here is the code to send data from one domain to another using curl in php*     `$url='http://training3.mbincbs.com/karma/phpcontact.php';
$s = curl_init();
curl_setopt($s,CURLOPT_URL, $url); 
curl_setopt($s, CURLOPT_POST, 1);
curl_setopt($s, CURLOPT_POSTFIELDS,

        "contactmessage=".$message."&contactname=".$name."&contactemail=".$email."&contactsubject=".$subject);

curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
`$Name = $_POST["contactname"];
`$Email = $_POST["contactemail"];
`$Subject = $_POST["contactsubject"];
`$Message = $_POST["contactmessage"];