0

I have a contact form on my site. It can either use PHP script to capture data and email it to me, or send it to API directly, by changing <form action="">

By API i mean a script that captures info and saves it to external DB. The API is based on ASP (this is my presumption), and I have no access to it, and have to use the format specified below.

I need to modify the PHP script, so it send info by email AND to the external API using this SPECIFIC format using POST method.

Disclaimer: I'm not a programmer, but I can figure our how to do things, if pointed in the right direction.

The format in wich API accepts info:

<form action="https://api.somsite.com/?user=&key=&zipcode=&name=&phone=&email=&address=&service=" method="post">

<input type="hidden" name="user" value="12345"/>
<input type="hidden" name="key" value="0987654321"/>

Hidden values (USER and KEY) are used so API knows where info came from.

Other inputs are provided by user (Name, Email, Zip, Phone, Address, Service).

Here is what my current PHP script looks like:

<?php session_start(); ?><?php

$to = "myemail@gmail.com";
$subject = "LEAD";
$email = $_REQUEST["email"];
$name = $_REQUEST["name"];
$address = $_REQUEST["address"];
$zip = $_REQUEST["zipcode"];
$phone = $_REQUEST["phone"];
$service = $_REQUEST["service"];
$user = $_REQUEST["user"];
$key = $_REQUEST["key"];

$dodgy_strings = array(
                "content-type:"
                ,"mime-version:"
                ,"multipart/mixed"
                ,"bcc:"
);

$msg = 'Name: '.$name. PHP_EOL;
$msg .= 'Phone: '.$phone. PHP_EOL;
$msg .= 'E-mail: '.$email. PHP_EOL. PHP_EOL;
$msg .= 'Address: '.$address. PHP_EOL;
$msg .= 'Zip code: '.$zip. PHP_EOL. PHP_EOL;
$msg .= 'Service: '.$service. PHP_EOL. PHP_EOL;
$msg .= 'User ID: '.$user. PHP_EOL. PHP_EOL;
$msg .= 'Access Key: '.$key. PHP_EOL. PHP_EOL;
$msg .= PHP_EOL;

mail($to, $subject, $msg);

header('Location: http://www.mysite.com/thankyou.htm'); // This redirects to Thank You page

?>

Basically, I need to use the above PHP script together with some sort of CURL function, or similar.

I read somewhere on STACK that I would need to us CURL function in PHP, but have no idea how to implement it.

Please help - I would appreciate it VERY VERY much.

Sincerely, Leo.

4

2 回答 2

0

这是一个超时 5 秒的 curl 调用示例,用于发布数据。结果 $data 变量是调用的结果页面。

$url='http://www.website.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,5); 
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$postdata = array(
    'post_variable1'=>'post_value1'
    );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch); 

编辑:使用此示例,您可以按如下方式传递 POST 变量,从而替换我在上面设置 $postdata 的位置 -

$postdata = array('email'=>$_POST['email'], 'phone'=>$_POST['phone']);
于 2013-07-10T22:49:52.977 回答
-2

您需要做的就是将您的表单方法编辑为method="get".

当您使用方向 url 时,您会丢失您的信息。你可以修复它。

<form action="ContactUs.php" method="get">

希望它有所帮助。

于 2013-07-09T18:21:14.440 回答