Computer Hope

Internet & Networking => Web design => Topic started by: Zylstra on March 31, 2006, 09:54:15 PM

Title: Making forms (not forums)
Post by: Zylstra on March 31, 2006, 09:54:15 PM
I have Dreamweaver, and I would like to know how to make it so a form send information to a specific email address. I have no idea whatsoever of how to do this.
Title: Re: Making forms (not forums)
Post by: Flame on April 01, 2006, 05:54:35 AM
I had the same question a while ago. This will help you. Read the instructions carefully. http://www.webmaster-talk.com/php-forum/35929-feedback-form.html ... For other website questions, you might try http://www.webmaster-talk.com  :)

Flame
Title: Re: Making forms (not forums)
Post by: Zylstra on April 01, 2006, 12:08:56 PM
OK,
Looks simple and easy (not what I thought it would be)
I will mess around with that code and see if I can get it.
Thanks
Title: Re: Making forms (not forums)
Post by: Flame on April 01, 2006, 01:05:55 PM
Sure thing. Keep us posted on how you do. As usual, come back and see us if you have any more questions as well  ;)

Flame
Title: Re: Making forms (not forums)
Post by: Zylstra on April 01, 2006, 03:00:24 PM
When I click "Send the Form" it goes the the Pagetwo.php, but gives me the code.

It shows this:

<?php

$body_of_message= $_POST['message']. "\n";
$body_of_message .= "Sent by " . $_POST['name'];
$subject= "Message from the feedback form";

if(mail("[email protected]",$subject,$body_of _message)) {
echo "Your message was sent.";
} else {
echo "There was a problem.";
};

?>


It does not send anything. What do I do to fix the problem?
Title: Re: Making forms (not forums)
Post by: Rob Pomeroy on April 01, 2006, 10:00:25 PM
It's easy enough to design the form, but then you need a program to process the data sent by the form.  In this case, the data is being sent to a PHP (http://www.php.net) script.  If you don't have a PHP-enabled webserver, this will not do you any good.
Title: Re: Making forms (not forums)
Post by: Flame on April 02, 2006, 08:06:16 AM
Check into that. Who is your host? We need to make sure they support PHP... Good point Rob  :)

Flame
Title: Re: Making forms (not forums)
Post by: Franky on April 02, 2006, 08:43:39 AM
Hey,

Well I'm in Information Technology and I have done a lot of dreamweaver and forms in my Web course. To send form information to an e-mail address, you have to include the following after your first or second heading in your code:

<form action="mailto: email_address?subject = Send" method="post" enctype="text/plain">

Some email servers will let you open the browser automatically when the button is pressed. Some you might not be able to. Also, depending on your e-mail configuration, you may receive warning dialog boxes or be given a chance to edit the e-mail message.

Hope it helps!
Title: Re: Making forms (not forums)
Post by: Mindwr@ck on April 20, 2006, 10:51:46 PM
Sometimes seeing code is better at helping you learn it. Here is a simple form that is commented so you can see what to change and what each section does. This example does require you to have a PHP enabled server. Hope this helps!

Code: [Select]
<?php
echo "      <center>";

//BEGIN PROCESSING EMAIL 
if ($_POST['name']){

//CHECK YO SEE IF REQUIED FIELDS ARE EMPTY      
      
if(empty($_POST['name']) &#124;&#124; empty($_POST['email'])){

//IF A REQUIRED FIELD IS EMPTY SHOW THIS TO USER
      
echo "      <div class='plaintext'><br />Please fill out the form completly</div><br />";
      
      }

//IF ALL FIELDS ARE FILLED OUT SEND THE MESSAGE INFORMATION
      
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$name."
Email: "
.$email."
Yahoo: "
.$yahoo."
MSN: "
.$msn."
Comments: "
.$Comments."
"
;
$message stripslashes($message);

//EDIT REQUIRED:::::::::::CHANGE [email protected] TO YOUR EMAIL ADDRESS
//EDIT REQUIRED:::::::::::CHANGE FROM: YOUR WEBSITE TO FROM: <WHAT YOU WANT>
mail("[email protected]","Contact Us Form Submitted",$message,"FROM: YOUR WEBSITE");
//END PROCESSING EMAIL

//BEGIN SHOWING WHAT THE USER SUBMITTED
echo "      <div class='txtSession'>Thank you. You input this information.</div>";

echo 
"      <table width=75%>";

echo 
"      <tr>";
echo 
"      <td><div class='txtSession'>Name:</div></td>";
echo 
"      <td><div class='txtSession'>$name</div></td>";

echo 
"      </tr><tr>";

echo 
"      <td><div class='txtSession'>Email:</div></td>";
echo 
"      <td><div class='txtSession'>$email</div></td>";

echo 
"      </tr><tr>";

echo 
"      <td><div class='txtSession'>Yahoo:</div></td>";
echo 
"      <td><div class='txtSession'>$yahoo</div></td>";

echo 
"      </tr><tr>";

echo 
"      <td><div class='txtSession'>MSN:</div></td>";
echo 
"      <td><div class='txtSession'>$msn</div></td>";

echo 
"      </tr><tr>";

echo 
"      <td><div class='txtSession'>Comments:</div></td>";
echo 
"      <td><div class='txtSession'>$Comments</div></td>";

echo 
"      </tr>";

echo 
"      </table>";
//END SHOWING WHAT THE USER SUBMITTED
}
}

//BEGIN THE CONTACT FORM
echo "      <br/><br/>";

echo 
"      <form method='post' action='contactus.php' target='_self'>";

echo 
"      <table width='75%' border='0'>";

echo 
"      <tr>";

echo 
"      <td><div class='txtSession'>Name *</div></td>";
echo 
"      <td><input type='text' size='30' name='name' class='textbox'></td>";

echo 
"      </tr><tr>";

echo 
"      <td><div class='txtSession'>Email *</div></td>";
echo 
"      <td><input type='text' size='30' name='email' class='textbox'></td>";

echo 
"      </tr><tr>";

echo 
"      <td><div class='txtSession'>Yahoo</div></td>";
echo 
"      <td><input type='text' size='30' name='yahoo' class='textbox'></td>";

echo 
"      </tr><tr>";

echo 
"      <td><div class='txtSession'>MSN</div></td>";
echo 
"      <td><input type='text' size='30' name='msn' class='textbox'></td>";

echo 
"      </tr><tr>";

echo 
"      <td><div class='txtSession'>Comments</div></td>";
echo 
"      <td>&nbsp;</td>";

echo 
"      </tr><tr>";

echo 
"      <td colspan='2'><textarea cols='50' name='Comments' rows='5' class='textbox'>Give us your feedback, good or bad!</textarea></td>";

echo 
"      </tr>";

echo 
"      </table>";
     
echo 
"      <div align='center'><input type='submit' value='Submit Form'>  <input type='reset' value='Clear Form'></div>";

echo 
"      </form>";
//END THE CONTACT FORM
echo "      </center>";
?>
Title: Re: Making forms (not forums)
Post by: Zylstra on June 22, 2006, 02:42:41 PM
(later responce, better server, more fun!)
OK, now I get this:
Parse error: syntax error, unexpected T_STRING in /home/jessez/public_html/password_content/process_request.php on line 39
Title: Re: Making forms (not forums)
Post by: Rob Pomeroy on June 22, 2006, 03:11:39 PM
Please post the section of code that includes that line.  I'll need to see the line immediately above it for debugging purposes.  Please clearly indicate which is the correct line, 'cause I ain't gonna count it for you.  ;)
Title: Re: Making forms (not forums)
Post by: Zylstra on June 22, 2006, 06:30:43 PM
Ok, I didn't know that I needed the same code for this. Since all of this, the file has been modified.
The new error code is this:
Parse error: syntax error, unexpected T_STRING in /home/jessez/public_html/password_content/process_request.php on line 8

Here's the actual code, with lines and numbers.
Code: [Select]
1  |<p>
2  |  <?php
3  
&#124;
4  &#124;$body_of_message= $_POST['message']. "\n";
5  &#124;$body_of_message .= "Sent by " . $_POST['name'];
6  &#124;$subject= "Message from the feedback form";
7  &#124;
8  &#124;if(mail("[email protected]",$subject,$body_of _message)) {
9  &#124;echo "Your message was sent.";
10&#124;} else {
11&#124;echo "There was a problem.";
12&#124;};
13&#124;
14&#124;?>

15|</p>
16|

And just for everyone's entertainment, a screenshot of this is included
Title: Re: Making forms (not forums)
Post by: Rob Pomeroy on June 23, 2006, 02:33:46 AM
Got it.  It was very hard to spot!

On the line
if(mail("[email protected]",$subject,$body_of _message)) {
you have a space in the middle of the variable name, "$body_of _message", before the second underscore.  Delete it.  :)
Title: Re: Making forms (not forums)
Post by: Zylstra on June 23, 2006, 02:01:31 PM
"Your message was sent."
unless there's a hidden side to that message, everything is working. Thanks!

But that wasn't the only problem, the email address was wrong. But I fixed that to.

All seems to be well, now to see if it sends understandably.

Edit:
oh great.
All I see in the message is this:

From [email protected] Fri Jun 23 15:00:22 2006
Return-path: <[email protected]>
Envelope-to: [email protected]
Delivery-date: Fri, 23 Jun 2006 15:00:22 -0500
Received: from nobody by orbit.serverz.org with local (Exim 4.52)
    id 1FtrpF-0004w3-Rn
    for [email protected]; Fri, 23 Jun 2006 15:00:21 -0500
To: [email protected]
Subject: Message from the feedback form
Message-Id: <[email protected]>
From: Nobody <[email protected]>
Date: Fri, 23 Jun 2006 15:00:21 -0500
Status: R  Simple headers  

Sent by
 
Title: Re: Making forms (not forums)
Post by: Rob Pomeroy on June 24, 2006, 12:32:51 AM
Are you sure that POST variables are reaching this form?  You can test by echoing them within your script (commenting out the mail section until you have verified that part is working.
Title: Re: Making forms (not forums)
Post by: Zylstra on June 24, 2006, 12:55:45 PM
I bet you that I dont have any "POST" variables. I bet there all set to "GET"

Lets find out...


connecting to remote server...
sorting list of remote folders...
It was set to "GET"
I changed it to "POST"
I will see what happens now.


-----POST MERGE-----


Changed "GET" to "POST" and it didnt work.
 
I did give the server time to update.  
 
All I get is:
 
Date: 6/24/2006 14:01:14 -0500
From: Nobody <[email protected]>
To: [email protected]
Subject: Message from the feedback form  All headers  
 
Sent by  
 
  
 
 
 
and nothing more. What could be the problem?
 
 
(BTW: Im not the best at this "form" stuff. It could just be a simple error or something missing. But I dont know what.)
Title: Re: Making forms (not forums)
Post by: Zylstra on June 24, 2006, 01:09:53 PM
4| $body_of_message= $_POST['message']. "\n";
5| $body_of_message .= "Sent by" . $_POST['name'];

I see the words "Sent By" in each message I get.
Should the above lines have something different?
Title: Re: Making forms (not forums)
Post by: Rob Pomeroy on June 24, 2006, 02:32:23 PM
At the top of your script please add the following:
<?php print_r($_POST); ?>
Please then show the results - this will print the contents of the $_POST array.
Title: Re: Making forms (not forums)
Post by: Zylstra on June 24, 2006, 02:38:03 PM
This appears when you submit the form

Array
(
    [name_nickname] => name
    [date_created] => date
    [My_notes_to_add_on_site] => notes
    [my_email] => email
    [show_my_email] => checkbox
    [my_commet] => commets
    [my_website] => website
    [I_agree_to_let_you_change_my_notes_name_and_any_info_you_provide_to_me] => checkbox
    [Send] => Send
)

Your message was sent.

Email recived shows as:
Sent by



I have made a special directory on my site to show what this is supposed to do, it contains most of the previous code, but was somewhat altered.

Please visit www.jessez.mbhosting.com/chtest/ for more information