Forum Moderators: coopster
html form
<FORM action="sendmail.php" method="POST">
<table border = "0">
<tr>
<td>First name: </td>
<td><INPUT type="text" name = "firstname" size = "60"></td>
</tr>
<tr>
<td>Last name: </td>
<td><INPUT type="text" name = "lastname" size = "60"></td>
</tr>
<tr>
<td>Email: </td>
<td><INPUT type="text" name = "email" size = "60"></td>
</tr>
..
.
.
.
.</html>
php script
<?
print "Content-type: text/html\n\n";
$firstname=$_GET['firstname'];
$lastname=$_GET['lastname'];
$email=$_GET['email'];
$sex=$_GET['sex'];
..
.
.
.
$data="\rFirst Name: "."$firstname"."\t"."Last Name: ".$lastname."\t"."Email: ".$email."\t"."Sex: ".$sex."\t"."Year of Passing: ".$yr_pass."\t"."Course Taken: ".$course."\t"."IT Roll No: ".$it_roll."\t"."Current Employer: ".$employer."\t"."Give a talk: ".$present."\t"."No of Guests: ".$guests."\n";
$fh = fopen("data.txt","a");
fwrite($fh,$data);
fclose($fh);
echo "Your data has been recieved, thank you.";
?>
please help me out..
For more information regarding the difference between $_GET and $_POST, refer to the Predefined Variable Documentation [us2.php.net].
You will find your experience at this community pleasant and informing!
print "Content-type: text/html\n\n";
By default, all PHP output is sent as HTML. So there is no need to specify the content-type, contrary to Perl.
Also, if you do need to specify the content-type, send a header:
header("Content-type: text/plain"); edit: all this is less relevant if you're trying to mail something...
[edited by: RonPK at 4:40 pm (utc) on Sep. 19, 2006]
thanks in advance.
abhishek
edit: one more thing, i would like to ask...why do i have to add the line #!D:\PHP\install\php.exe
in the beginning of the script, failing which i get the following error log:
D:/WEB_ROOT/sendmail.php is not executable; ensure interpreted scripts have "#!" first line.....please throw some light..
$host = $_REQUEST[host];
$port = $_REQUEST[port];
$user = $_REQUEST[user];
$pass = $_REQUEST[pass];
the field names should NOT be enclosed in any quotes, and following the case of vars from the form vars is not a bad idea either.
re: #!D:\PHP\install\php.exe
Means you're running the script as a CGI app, and not with the server module -- as such PHP.exe must be found and run everytime you call the script -- why this happens is the way you installed PHP in Apache -- there should be two different directories for the two ways of running PHP.
# The module runs scripts here...
Alias /php/ "C:/php/"
# This is actually the CGI directory...
ScriptAlias /php-cgi/ "C:/php/cgi/"
ScriptAlias forces the CGI method for apps in the specified path, whereas when the module is installed, PHP scripts can be run anywhere in the server tree unless restricted by other Apache directives.