How to submit forms on other sites
Posted: Sun Feb 25, 2007 6:03 pm
How can I submit forms in php that are on other sites. for example, have a script that will fill out this post form and submit it.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$post_data = array();
$post_data['pictures[0]'] = "@cat.jpg";
$post_data['pictures[1]'] = "@dog.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://my.domain.com/my_url.php" );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
print "$postResult";
?>Code: Select all
<?php
$post_data = array();
$post_data['subject'] = "the subject";
$post_data['message'] = "the message";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.simsportal.net/test.php" );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
print "$postResult";
?>Code: Select all
<?
include("includes.php");
if(isset($_POST['Submit']))
send_mail("william@po2mob.com",$_POST['subject'],$_POST['message']);
?>
<form name="form1" method="post" action="">
<input name="subject" type="text" id="subject">
<br>
<input name="message" type="text" id="message">
<br>
<input type="submit" name="Submit" value="Submit">
</form>Code: Select all
<?php
$post_data = array();
$post_data['subject'] = "the subject";
$post_data['message'] = "the message";
$post_data['Submit'] = "Submit";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.simsportal.net/test.php" );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
print "$postResult";
?>Only one way to find out for yourself..psychotomus wrote:is it supose to be like this?
curl_setopt($ch, CURLOPT_POSTFIELDS, 'message=MESSAGE&subject=SUBJECT&Submit=Submit);