drfals1307 2013-07-12 15:28
浏览 66
已采纳

将php变量从一个服务器转移到另一个服

I have a contact form which post the input to a .php file located in my server.
some of the code:

$name_field = $_POST['name'];
$email_field = $_POST['email'];
$phone_field = $_POST['phone'];
$message_field = $_POST['message'];

In my server I can't use php mail(), so I want to transfer this variables to another .php file located in other domain.

I know I can do it directly in the form

action="http://otherdomain.com/contact.php"

but I want the php script to be on my server and "Behind the scenes" transfer the variables. My first question is if it possible to do so in this way? and the second, how to...

  • 写回答

2条回答 默认 最新

  • dongshen9686 2013-07-12 15:35
    关注

    You will want to use 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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度