FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP: Feedback form issues.. help =P





Helios
I've started to learn PHP today and I have some issues with my first feedback script.

After I fill all the info and send it for processing it works fine, but the email the I recieve contains only the strings that i've entered and not the vars.


example: after processing the info i get this email:
Code:
Message from  ()

Messege:


but there is no text after From: and Messege:


look at the code and tell me what's wrong..



Code:

<html>
<body>

<?php
if ($_POST)
{
   //define vars
   $name = $_POST['name'];
   $email = $_POST['email'];
   $messege = $_POST['messege'];
   $to = "helios1234@gmail.com";
   $subject = "Feedback";
   $body = "Message from $name ($email)\n\nMessege:\n\n$messege\n";
   //mail
   mail($to, $subject, $body);
   echo 'Done!';
}else{


?>

<center>
<table width="417" border="1">
  <tr>
    <td width="199"><table width="199" height="375" border="0">
      <caption align="top">
      <strong>      Personal info
      </strong>
      </caption>
      <tr>
        <td height="155" scope="col"><div align="left">
          <p>Your E-Mail Address  : </p>
          <p>           <form action="<?= $PHP_SELF ?>" method="post">
                     <input name="email" type="text" id="email">
                  </form>           
          </p>
        </div>
          </td>
      </tr>
      <tr>
        <td><p>Your name:</p>
          <p>
            <form action="<?= $PHP_SELF ?>" method="post">
            <input name="name" type="text" id="name">
         </form>
          </p>
          </td>
      </tr>
    </table> </td>
    <td width="202">
<table width="200" height="336" border="0">
  <caption align="top">
  <strong>Messege</strong>
  </caption>
  <tr>
    <td scope="col"><div align="left">
      <p>Your messege:</p>
      <form name="form1" method="post" action="">
        <textarea name="textarea"></textarea>
      </form></p></div>
      </td>
  </tr>
</table>
</td>
</tr></table>
<form action="<?= $PHP_SELF ?>" method="post">
  <input type="submit" name="Submit" value="Send!">
</form>
</center>

<?php

}

?>
</body>
</html>




http://helios.frihost.net/php/test.php
mathiaus
change
Code:
   $body = "Message from $name ($email)\n\nMessege:\n\n$messege\n";

to
Code:
   $body = "Message from " .$name. "(" .$email. ")\n\nMessage:\n\n" .$message. "\n";



Your form needs work as well. to start with all fields should be under the same <form> not seperate! And your textarea is named textarea at the moment but during processing your looking for a field called messege which doesnt exist.

Complete working code for you. I added some headers for from and reply to so you could remove the "Message from name (email)" line if you wanted.

Code:
<html>
<body>

<?php
if ($_POST)
{
   //define vars
   $name = $_POST['name'];
   $email = $_POST['email'];
   $message = $_POST['message'];
   $to = "*****@gmail.com";
   $subject = "Feedback";
    $body = "Message from " .$name. " (" .$email. ")\n\nMessage:\n\n" .$message. "\n";
   $headers = "From: " .$email. "\r\n" . "Reply-To: " .$email;
   //mail
   mail($to, $subject, $body, $headers);
   echo 'Done!';
}else{


?>
<form action="" method="post" name="feedback">
<table width="417" border="1" style="margin: auto;">
  <tr>
    <td width="199"><table width="199" height="375" border="0">
      <caption align="top">
      <strong>      Personal info
      </strong>
      </caption>
      <tr>
        <td height="155" scope="col"><div align="left">
          <p>Your E-Mail Address  : </p>
          <p>
                     <input name="email" type="text" id="email">
         
          </p>
        </div>
          </td>
      </tr>
      <tr>
        <td><p>Your name:</p>
          <p>
            <input name="name" type="text" id="name">

          </p>
          </td>
      </tr>
    </table> </td>
    <td width="202">
<table width="200" height="336" border="0">
  <caption align="top">
  <strong>Message</strong>
  </caption>
  <tr>
    <td scope="col"><div align="left">
      <p>Your message:</p>
<textarea name="message" cols="30" rows="5"></textarea>
</p></div>
      </td>
  </tr>
</table>
</td>
</tr></table>

  <input type="submit" value="Send!">
</form>


<?php

}

?>
</body>
</html>
Helios
Ok, I see..
So I can't put vars between quotes and I have to put only 1 Form tag..

I have few questions..

1. what's \r ?
2. Can you explain about the POST and GET a little bit..?
3. What was the problem with my script, why didn't it send those vars by mail? Because they were under quotes or because I put multiple form tags?

also i heard that you can insert these lines to the header and you can create HTML email..
like this:
Code:

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

I can google for MIME but what's this ".=" ???
mathiaus
1 wrote:
well it just sort of seperates the different types of headers. Not really jusre exactly what it does other than that. All i know is that it's needed! Smile



2 wrote:
really simple. 2 types of form method. post and get.
POST - posts the form data ie. sends the data to wherver the action sends it to. Script picks the data up through $_POST['fieldname'].
GET - no data actually sent. Instead form sends user to wherever the action command sends it and adds variables onto the end
eg. action sends to process.php and fiels are name and email. the url of the page you are directed to will be
process.php?name=****&email=****@gmail.com
To then get this information you use $_GET['url variable']
Get is not resticted to forms!



3 wrote:
Both but mainly the form problem. One form a field Confused
You can only send one form. All fields were differnt forms so when clicking submit you were sending whatever fields were in the form where submit was. There werent any. The actual mail sometimes sends the variables whilst still in quotes but wont always so its best to take them out.



4 wrote:
Yes you can do that. See this page for full details http://uk.php.net/manual/en/function.mail.php
just rember that the whole thing is in quotes so if used within the html you'll need to put a backward slash before any quotes used witin your html!
ie <table style=\"width: 100%\">



5 wrote:
'.' in php means and/also, and '=' means equals so it means 'and also equal to'
eg $myname = "**"; $myname .= " **";
If I was to echo $myname I would get "matthew foody". You can add as mutch as you like. It saves having to do something like
$myname = "**"; $myname = $myname . " **";



Hope that helps Smile
Helios
Wow thank you man. Your answers helped me a lot.

Now I made a registration form with PHP/MySQL =)

Tomorrow i shall continue! Surprised Laughing
rollespil
I see your problem, there might be two things wrong:

1. Your code are wrong, you should find a site with some codes or change em yourself if you prefer. In case you want help check http://www.hotscripts.com.

2. Some sites wont accept the methods $_GET or $_POST if you are not a paying member Evil or Very Mad Evil or Very Mad Evil or Very Mad Evil or Very Mad
mathiaus
rollespil wrote:
I see your problem, there might be two things wrong:

1. Your code are wrong, you should find a site with some codes or change em yourself if you prefer. In case you want help check http://www.hotscripts.com.

2. Some sites wont accept the methods $_GET or $_POST if you are not a paying member Evil or Very Mad Evil or Very Mad Evil or Very Mad Evil or Very Mad


Already solved Wink

-close-
Related topics
A Simple Form Mail in PHP
Some php probs..need some help plzz!
php dropdown lists with if statements or switch
Php parsing error! Need help
Need help with php
Anyone care to help me with a simple PHP Form ?
I am a PHP newbie, so please help me
I need a complex php/flash form... 250FRIH$
A simple multiple choice mail form
PHP Form Question
AJAX and PHP contact form
How to build simple PHP upload form
Help required with Captcha script
Contact Form Issues
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.