PDA

View Full Version : PHP FAQ



Jseb
14-04-2005, 01:10 AM
Hi everyone! I wrote down a Form Contact with 2 page to send it to a email!

Here the first page Form!


<form action="contactme.php" mehod="post">
<table border="1" cellspacing="1" width="100%" id="AutoNumber20" style="border-width: 0">
<tr>
<td width="10%" style="border-style: none; border-width: medium"><font face="Verdana" size="1" color="#ECECFF">Habbo Name:</font></td>
<td width="1%" style="border-style: none; border-width: medium">&nbsp;</td>
<td width="89%" style="border-style: none; border-width: medium">
<input type="text" name="name" size="20"></td>
</tr>
<tr>
<td width="10%" style="border-style: none; border-width: medium"><font face="Verdana" size="1" color="#ECECFF">Habbo Hotel:</font></td>
<td width="1%" style="border-style: none; border-width: medium">&nbsp;</td>
<td width="89%" style="border-style: none; border-width: medium">
<font face="Verdana" size="1"><select size="1" name="Hotel">
<option selected>-- Select One --</option>
<option>Habbhotel.Com</option>
<option>HabboHotel.Co.Uk</option>
<option>HabboHotel.Ca</option>
<option>Habbohotel.Au.Com</option>
<option>Other</option>
</select></font></td>
</tr>
<tr>
<td width="10%" style="border-style: none; border-width: medium"><font face="Verdana" size="1" color="#ECECFF">Email:</font></td>
<td width="1%" style="border-style: none; border-width: medium">&nbsp;</td>
<td width="89%" style="border-style: none; border-width: medium">
<input type="text" name="Email" size="20"></td>
</tr>
<tr>
<td width="10%" style="border-style: none; border-width: medium"><font face="Verdana" size="1" color="#ECECFF">Subject:</font></td>
<td width="1%" style="border-style: none; border-width: medium">&nbsp;</td>
<td width="89%" style="border-style: none; border-width: medium">
<input type="text" name="Subject" size="20"></td>
</tr>
<tr>
<td width="10%" style="border-style: none; border-width: medium"><font face="Verdana" size="1" color="#ECECFF">Message:</font></td>
<td width="1%" style="border-style: none; border-width: medium">&nbsp;</td>
<td width="89%" style="border-style: none; border-width: medium">
<textarea rows="6" name="comments" cols="29"></textarea></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1"></p>
</form>

And here the Contactme.php!


<?PHP
$to = "[email protected]";
$re = "Contact Us";
$hotel = $Hotel;
$mail = $Email;
$msg = $comments;
$name = $name;
$sub = $Subject;
mail($to,$name,$hotel,$mail,$msg);
?>

Unfortunotly its doesnt bring me all the information! That i want and i believe my mistake will be on contactme.php page! But why and how?

BTW i am new at php! I just learn how today how to save a page in php with frontpage! But i am a fast learning and since a i do a lot of c++ and i am expert at it! I understood the fact that they were variable giveway + mail is what will be find in the mail!

Mentor
14-04-2005, 11:33 AM
ok a few problems

First off to get the varible from the forum. use.

$name = $_POST['name'];


if the subjcets name was name. athogh teh varible itslef could be anything.

so all of your varibles would be


$hotel = $_POST['Hotel'];
$email = $_POST['name'];
$name = $_POST['Email];
$subject = $_POST['subject'];
$comments = $_POST['comments'];

then you woul combine the data in to a singel varible to be the message

$mess = "$name ( $email ) \n on the $hotel Hotel. \n \n sent: \n $comments";


as an exsample.

the $name vearibela nd others get convrted to the other vaules.

the next problme is the mail function as its layed out like ths.
aka, email(resipiant) is fist bit, email subject is next, the message next, then if you want who its from.
the message varible should be set with data from other varibles.
mail ($Email, $Subject, $msg, $From);

so a basic email thing would be



<?php
$hotel = $_POST['Hotel'];
$email = $_POST['name'];
$name = $_POST['Email];
$subject = $_POST['subject'];
$comments = $_POST['comments'];

$mess = "$name ( $email ) \n on the $hotel Hotel. \n \n with the subject: $subject \n sent: \n $comments";

$to = "[email protected]";
$from = "From: [email protected] \r\n";

mail ($to, $subject, $mess, $from);
?>


for eg.

Athogh if you want to stop it bening spammed (aka this wayit would send an emial if ist viewed directly in the browers. you could ad a simple mesuer



<?php
if ($_SERVER['REQUEST_METHOD'] != 'GET'){

$hotel = $_POST['Hotel'];
$email = $_POST['name'];
$name = $_POST['Email];
$subject = $_POST['subject'];
$comments = $_POST['comments'];

$mess = "$name ( $email ) \n on the $hotel Hotel. \n \n with the subject: $subject \n sent: \n $comments";

$to = "[email protected]";
$from = "From: [email protected] \r\n";

mail ($to, $subject, $mess, $from);

}
else
{
echo "You may not view this page directly";
}
?>

Jseb
14-04-2005, 08:47 PM
hmm its seem great! And now no more code problem except that! ITs send me a message like this


( )
on the Hotel.

with the subject:
sent:

So they his where the variable are gone? its doesnt gave the name, the email the hotel, the subject and the message! and here the script!


<?php
$hotel = $_POST['Hotel'];
$email = $_POST['name'];
$name = $_POST['Email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];

$mess = "$name ( $email ) \n on the $hotel Hotel. \n \n with the subject: $subject \n sent: \n $comments";

$to = "[email protected]";

mail ($to, $subject, $mess, $from);
$from = "Contact Page";

?>

so its seem great exept this line in red!Why? but thx for the rest of it!

Mentor
14-04-2005, 08:52 PM
ok. i may have made a few mistakes, as name and email have been mixed up.

In the form itself. Each input has a name

( name="whatever")

then the varibles are tacken by this

$_POST['whatever];

the orgnal name, being where whatever is.
check all that corisponds correctly

aslo another problem i noticed was



$email = $_POST['name'];
$name = $_POST['Email'];

should be


$name= $_POST['name'];
$email = $_POST['Email'];


aslo some server configrtiosn wont like the short cut so try this



$mess = "".$name." ( ".$email." ) \n on the ".$hotel." Hotel. \n \n with the subject: ".$subject." \n sent: \n ".$comments."";

Jseb
14-04-2005, 09:07 PM
still showing no message why :S

Here i took my first code from this::

Step 1:: Make a page called contact.php and paste this code into it.


<form action="contactme.php" mehod="post">
<p align="center">
<b><font size="2" face="Verdana">Name: <input type="text" name"username" size="30"/>
<br>
<br>
Email: <input type="text" name="useraddr" size="30">
<br>
<br>
Message: <textarea name="comments" cols="30" rows="5"> </textarea>
<br>
<br>
<input type="submit" value="Send Form"> </font></p>
</form></b>

Step 2:: Make a new page and paste the code below into it and name it contactme.php


<?PHP
#Where you want the email to go
$to = "[email protected]";

#subject of the message, change this
$re = "Feedbackfromcontactpage";

#message from the feedback form, don't touch this
$msg = $comments;

#send the mail, don't edit this
mail($to,$re,$msg);
?>

And use to work really great but i wan to add some field so i did them! but should i just send it by mail($to,$etc....)

Mentor
14-04-2005, 09:16 PM
i noticed an error, heres a redue if the code



<?php
if ($_SERVER['REQUEST_METHOD'] != 'GET'){

$hotel = $_POST['Hotel'];
$name= $_POST['name'];
$email= $_POST['Email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];

$mess = "".$name." ( ".$email." ) \n on the ".$hotel." Hotel. \n \n with the subject: ".$subject." \n sent: \n ".$comments."";

$to = "[email protected]";
$from = "From: [email protected] \r\n";

mail ($to, $subject, $mess, $from);

}
else
{
echo "You may not view this page directly";
}
?>

Jseb
15-04-2005, 07:43 PM
Hmm k well that newest thing i just well put it on and to see and all my thing were fill in however its just gave me the access of echo thing at the end else! didnt do the rigth one! why :S

-JT-
15-04-2005, 11:09 PM
i would recomend to one i used on digital designs


www.lp-revolution.com/digitaldesigns

Jseb
15-04-2005, 11:52 PM
And what script did u use? :P or is there a way so that i can get a scritp with a working form!

Want to hide these adverts? Register an account for free!