Submit the PHP Form data without using CURL

Your PHP Server (HOSTING) doesn’t enabled CURL, then we can submit the data using PHP Function’s like fsockopen() and fputs()

Please see the below Sample Code:


//create array of data to be posted
$post_data['last_name'] = trim($_POST['name']);
$post_data['email'] = trim($_POST['email']);
$post_data['company'] = trim($_POST['company_name']);

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//we also need to add a question mark at the beginning of the string
$post_string = '?' . $post_string;

//we are going to need the length of the data string
$data_length = strlen($post_string);

//let's open the connection
$connection = fsockopen('', 80);

//sending the data
fputs($connection, "POST  /SOURCE_URL.php  HTTP/1.1\r\n");
fputs($connection, "Host: \r\n");
"Content-Type: application/x-www-form-urlencoded\r\n");
fputs($connection, "Content-Length: $data_length\r\n");
fputs($connection, "Connection: close\r\n\r\n");
fputs($connection, $post_string);

//closing the connection



Written by 

I am Sakthivel Madesh, a certified Salesforce Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 13x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply