Page 1 of 1

Passing form information to the next page automatically

Posted: Fri Aug 27, 2004 8:07 am
by Antnee
Hey guys

I'm sure this is a real easy one for you but I'll be damned if I can find teh info I want anywhere!

I have created an 'internal messaging system' that allows our users to send each other messages throught the site, kind of like the private messaging service on this site, but I wanted to add an option to send by email too. I am using Form2mail to send the emails and I have modified a script that will pass the POSTed data to the Form2mail script. Problem is that I don't know how to pass it on.

Here is the page as I have it now (Note that it works fine until I chose the option to send email, I get nothing then, I don't know how to get it to send the form automatically:

Code: Select all

<?php
session_start(); 
header("Cache-control: private");

include ("../action/connect.php");

$send_to = $_POST["send_to"]; //-- username to send the mail to --//
$subject = $_POST["subject"]; //-- subject the mail is about --//
$from = $_POST["from"]; //-- username of the sender --//
$from_f	= $_POST["from_f"]; //-- firstname of the sender --//
$from_l	= $_POST["from_l"]; //-- lastname of the sender --//
$message = $_POST["message"]; //-- actual message to send --//
$important = $_POST["important"]; //-- if should be marked as important --//
$email = $_POST["email"]; //-- Will be "1" if should also send email --//

//-- Send the message to the internal inbox --//
mysql_query ("insert into message values('','$send_to','$from','$from_f','$from_l',now(),'1','$important','$subject','$message')");

//-- If email option is chosen, send an email as well --//
if ($email == "1") {
	$recemail		= mysql_query ("SELECT email FROM message WHERE username ='".$send_to."'");
	$sendersemail	= mysql_query ("SELECT email FROM message WHERE username ='".$from."'");
	?>
	<form action="../cgi-bin/form2mail.cgi" method="post">
	<INPUT type="hidden" name="recipient" value="<?=$recemail;?>">
	<INPUT type="hidden" name="subject" value="<?=$subject;?>">
	<INPUT type="hidden" name="realname" value="<?=$from_f." ".$from_l;?>">
	<INPUT type="hidden" name="email" value="<?=$sendersemail;?>">
	<INPUT type="hidden" name="comments" value="<?=$message;?>">

<!-- THIS IS WHERE I DONT KNOW HOW TO AUTOMATICALLY SUBMIT THIS INFO -->

	</form>
	<?php
	}else{
	header('Location: '."index.php");
}
?>

Re: Passing form information to the next page automatically

Posted: Fri Aug 27, 2004 8:30 am
by timvw
Antnee wrote:
I wanted to add an option to send by email too. I am using Form2mail to send the emails and I have modified a script that will pass the POSTed data to the Form2mail script. Problem is that I don't know how to pass it on.

Code: Select all

$send_to = $_POST["send_to"]; //-- username to send the mail to --//
$subject = $_POST["subject"]; //-- subject the mail is about --//
$from = $_POST["from"]; //-- username of the sender --//
$from_f	= $_POST["from_f"]; //-- firstname of the sender --//
$from_l	= $_POST["from_l"]; //-- lastname of the sender --//
$message = $_POST["message"]; //-- actual message to send --//
$important = $_POST["important"]; //-- if should be marked as important
You might want to use [php_man]isset[/php_man] to make sure the values are posted and [php_man]mysql_escape_string[/php_man] to clean the input...

Antnee wrote:

Code: Select all

//-- If email option is chosen, send an email as well --//
if ($email == "1") {
	$recemail		= mysql_query ("SELECT email FROM message WHERE username ='".$send_to."'");
	$sendersemail	= mysql_query ("SELECT email FROM message WHERE username ='".$from."'");
You have 2 options, either u use the mail function [php_man]mail[/php_man] or you use [php_man]curl[/php_man] to post the values to the form

Re: Passing form information to the next page automatically

Posted: Fri Aug 27, 2004 9:16 am
by Antnee
timvw wrote: You might want to use isset to make sure the values are posted and mysql_escape_string to clean the input...
That bit is not a problem, I know that the information I need is posted OK, I just need this information to be posted to the CGI script without any further input from the user.

As for the other suggestions, WAY over my head, sorry! I'm only a beginner at PHP (been at it a couple of weeks) and I've never programmed anything before, not even basic HTML!

Posted: Fri Aug 27, 2004 12:55 pm
by feyd
I've used this in the past:

Code: Select all

$ch = curl_init();
	curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 300);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );
	$html = curl_exec($ch);
read the [php_man]curl[/php_man] pages for details on: [php_man]curl_setopt[/php_man], [php_man]curl_init[/php_man], [php_man]curl_exec[/php_man] and play around with it.

Posted: Fri Aug 27, 2004 2:43 pm
by hedge
check the following link, this is how I do it using fsockopen

viewtopic.php?t=7063