View Full Version : Forms - how do I get info to my email?
Woody
07-31-2006, 06:53 AM
Hi, I am a newbie to CSS, but haven't a clue about forms and I'm not sure which forum to address this question - please help.
I have used the CSS form on a website I'm working on:
http://www.woodenteacher.org.uk/prospectus.html
the CSS is:
.cssform p{
width: 300px;
clear: left;
margin: 0;
padding: 5px 0 8px 0;
padding-bottom: 75px;
padding-left: 155px; /*width of left column containing the label elements*/
}
.cssform label{
font-weight: bold;
float: left;
margin-left: -155px; /*width of left column*/
width: 100px; /*width of labels. Should be smaller than left column (155px) to create some right margin*/
}
.cssform input[type="text"]{ /*width of text boxes. IE6 does not understand this attribute*/
width: 180px;
}
.cssform textarea{
width: 250px;
height: 150px;
}
/*.threepxfix class below:
Targets IE6- ONLY. Adds 3 pixel indent for multi-line form contents.
to account for 3 pixel bug: http://www.positioniseverything.net/explorer/threepxtest.html
*/
* html .threepxfix{
margin-left: 3px;
}
/* end of prospectus form */
and the xhtml is:
<form id="myform" class="cssform" action="">
<p>
<label for="user">Name</label>
<input type="text" id="user" value="" />
</p>
<p>
<label for="address">Address:</label>
<textarea id="address" rows="5" cols="25"></textarea>
</p>
<div style="margin-left: 150px;">
<input type="submit" value="Submit" /> <input type="Reset" value="reset" />
</div>
</form>
</div>
I am using a company called Streamline.net for my hosting, and they say that my account supports; PHP4, Pearl, and CGI, and I have my own personal CGI bin. I asked them for the script that I would need, but they basically said that I would have to find my own!
Help! I've read about Post/Get but I really don't know where to start.
ANY help will be very gratefully received.
Laura
ddadmin
07-31-2006, 09:11 AM
That's just the frontend of the form. In order to have it mailed to you, you need a form processing script on the server side, such as a PHP form script: http://php.resourceindex.com/Complete_Scripts/Form_Processing/
Woody
07-31-2006, 10:06 AM
Hi, thanks for putting me in the right forum, but I feel the link that you have given drops me in the deep end a little!
I would ideally like to use the CSS form that I have and apply PHP to it, if that is possible?
Sorry, I really am on a steep learning curve (again) - is there a link, or tutorial that could explain it from the ground up?:confused:
BLiZZaRD
07-31-2006, 10:11 AM
Basically what DD is saying is that your posted CSS and XHTML above are just the look of your form the visitor is filling out.
What you need next is a confirmation page. From that page you can include a php script that when the visitor clicks the "everything is okay" button the page will send you the email you need.
Check this link (http://www.giuseppecalbi.com/scripts/gc_formmail/?lan=en) out. (it is one from the link DD provided. :)
djr33
07-31-2006, 10:30 AM
The idea is that you send the data TO something from a page.
Your page is DONE.
But, you need another one.
That next one will take the now-sent data and do stuff with it, like add it to a database, make a new page out of it, or "simply" send to your email.
However, coding such a page can be complex if you don't know php/programming. It's certainly not something you can't do, but there is an easier solution.
If you are just emailing to yourself and you don't mind annoyingly formatted emails, just search for a form interpreter or for mailer.
They will give you a url and instructions for the form and mail it to you through their page, for free, though it'll put ads on the email or something along those lines.
<form action="nextpage.php" method="post">
Note that nextpage.php will be the URL (or path) of the next page... the one that interprets it. Theoretically, you can just put "mailto:some@one.com", but that requires the use of the visitor's personal email program (like outlook, etc.).
The action is where the data is sent... this can be a page you write, a free one, or an email, but as above, that's not the best. It could even be any file on the web, but unless it's designed to interpret the form, then it won't change anything.
The method is "post" as that is the most common one.
That will send data behind the scenes.
"get" appends it to the URL and sends it that way.
If you typed in "fred" in the "name" field and clicked send, you'd get something like this:
yourlocation.php?name=fred
You've probably seen that before.
It can get in the way, though, so post is a bit more common, I'd say. get has important uses too (like being able to use a link, not a form, by typing it into the URL the link goes to, etc.)
Woody
07-31-2006, 12:10 PM
Thanks for your advice BliZZaRD and djr33, I have taken your advice on board, and found some more info on the hosting company's site. I have done the following:
Added a .php file called "sendmail.php" whose code is:
<?
mail(Laura@Woodenteacher.org.uk", "Prospectus Request",
$message,"From: $name","address");
header(Location:http://www.Woodenteacher.org.uk/thankyou.html);
>?
and also a .html file called "thankyou.html" with the following code in it:
<p>
Thank you, your prospectus will be sent out to you shortly.
</p>
and also altered the xhtml form code to:
<form id="myform" class="cssform" action="sendmail.php" method="post">
<p>
<label for="user">Name</label>
<input type="text" id="user" value="" />
</p>
<p>
<label for="address">Address:</label>
<textarea id="address" rows="5" cols="25"></textarea>
</p>
<div style="margin-left: 150px;">
<input type="submit" value="Submit" /> <input type="Reset" value="reset" />
</div>
</form>
</div>
But when I test it I get the following error message:
Parse error: parse error, unexpected '@' in /home/fhlinux216/w/woodenteacher.org.uk/user/htdocs/sendmail.php on line 3
I feel that I am going in the right direction, but am still doing something wrong - does anyone know what!?
BLiZZaRD
07-31-2006, 01:23 PM
Try this:
<?php
$name = $_POST['name'];
$address = $_POST['address'];
$message = "The email you requested.\n\n";
$email = "Laura@Woodenteacher.org.uk", $_POST['email'];
mail($email, "Prospectus Request" , $message, "From: $name, $address <>");
header(Location:http://www.Woodenteacher.org.uk/thankyou.html);
?>
you are telling the php to use the items posted from the previous page, but in the php you don't tell them where. So you need to define them.
**This is untested, I am very tired, and only learning these post strings myself, LOL sorry if it doesn't work straight away :) **
Woody
07-31-2006, 02:31 PM
Thanks for that BliZZaRD, but it still gives an error message, this time it says:
Parse error: parse error, unexpected '@' in /home/fhlinux216/w/woodenteacher.org.uk/user/htdocs/sendmail.php on line 5
The only thing I can querry is on the form xhtml were it says:
<label for="user">Name</label>
<input type="text" id="user" value="" />
should there be something in there?
I don't know what a Parse error is!
Thanks for your help to date - especially from a different time zone!
Laura
BLiZZaRD
07-31-2006, 06:28 PM
Oops, sorry, forgot the " marks around the address. Edited the script above.
Try again and see what. if any, errors you get.
A parse error is: An error encountered during parsing of an input stream due to invalid syntax.
Basically it tells you "HEY! Something is wrong with your code and I can't read it! Go back and check that you don't have a " missing or something!" :)
Woody
07-31-2006, 07:00 PM
Hi again BLiZZaRD,
I have tried the ammended script, but still get a similar error message, namely:
Parse error: parse error, unexpected ',' in /home/fhlinux216/w/woodenteacher.org.uk/user/htdocs/sendmail.php on line 5
Any ideas?
djr33
07-31-2006, 07:34 PM
Yep. This line is wrong.
$email = "Laura@Woodenteacher.org.uk", $_POST['email'];
You can't have $x = $y, $z; That's trying to assign two things to one variable, or something.
Just pick one or the other:
$email = "Laura@Woodenteacher.org.uk";
//OR
$email = $_POST['email'];
The first will send to that email, and the second will send to whatever value is sent from the form with the name "email", so a text field name="email", for example.
What BLiZZaRD *meant* to say was:
<?php
$name = $_POST['name'];
$address = $_POST['address'];
$message = 'Address:' . "\n$address\n";
$email = 'Laura@Woodenteacher.org.uk';
mail($email, 'Prospectus Request', $message, 'From: "' . $name . '" <noreply@woodenteacher.org.uk>');
header('Location: http://www.woodenteacher.org.uk/thankyou.html');
?>:)
BLiZZaRD
08-01-2006, 02:07 AM
Aye, that's what I meant. LOL
My problem with this one is that I don't really see what she wants for sure. I mean obviously an emial sent when someone fills out the form...
But sent to who? Her? The person filling out the form? Or both? I decided both, hence including her email addy and the one submitted from the form.
But still, the email will be pretty worthless, no real "message". All I can guess is that she wants notification and a name/email of someone who filled out a form, so she could manually email the person later with something else??
Like wise... if that were the case, can't she just put the php send mail on the thankyoupage.html? So then it would send from the thank you page, the user would get the "echo "Thank You, your oder has been mailed to me." on the page, and skip the whole redirection thing?
Woody
08-01-2006, 06:33 AM
Hi thanks for all the info, sorry if I haven't explained myself well.
What I am trying to do, is if people visit the website and want a prospectus, they fill their name and address in, press the submit button. A thank you confirmation page comes up then that information (name and address) is sent to , in this case at the moment, the test site email address (Woodenteacher) which is then forwarded to me at my personal email address(eventually it will be set up at the client's email address/domain). I don't want any info sent to the person who is filling the form out.
What is happening, now that I have added Twey's code is when I put info into the form online and click submit the thankyou.html page comes up and when I check my email, I have a message sent with Prospectus Request in the subject line, but in the body of the email it just says 'Address:' So it is kind of working, put not giving me all the details.
Does that make sense?
That's because you should be using name not id as the identifiers for the form elements.
Woody
08-01-2006, 05:34 PM
That's great Twey, I am now getting the address field sent to me but not the name?
Does your form look like this:
<form id="myform" class="cssform" action="sendmail.php" method="post">
<p>
<label for="name">Name</label>
<input type="text" id="name" value="" name="name" />
</p>
<p>
<label for="address">Address:</label>
<textarea name="address" id="address" rows="5" cols="25"></textarea>
</p>
<div style="margin-left: 150px;">
<input type="submit" value="Submit" /> <input type="Reset" value="reset" />
</div>
</form>?
Woody
08-01-2006, 05:46 PM
Twey this is my form code:
<form id="myform" class="cssform" action="sendmail.php" method="post">
<p>
<label for="user">Name</label>
<input type="text" name="user" value="" />
</p>
<p>
<label for="address">Address:</label>
<textarea name="address" rows="5" cols="25"></textarea>
</p>
<div style="margin-left: 150px;">
<input type="submit" value="Submit" /> <input type="Reset" value="Reset" />
</div>
</form>
That would be why then. Replace it with the code above.
Woody
08-01-2006, 05:58 PM
Twey,
That is fantastic, and has sorted it!
Could I ask one last question, before I wrap up this thread?
When I press submit the thankyou.html comes up, but when I close that it closes everything(the rest of the website). I guess I need a target blank code, but I'm not sure where to put it within the PHP/form code?
I'd put it in the form:
<form id="myform" class="cssform" action="sendmail.php" method="post" target="_blank">
Woody
08-01-2006, 06:09 PM
:) Many thanks for all your help Twey(and all the other contributors), I've learnt a lot, and it is all running well now.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.