Click to See Complete Forum and Search --> : send a form to my email
chriscam19
04-01-2003, 09:50 AM
ok I have a huge form. can you view it at http://www.lsgc.info and click on the questionaire link. Ok after someone fills out that form and clicks on submit I want it to be sent to my email account so I can view all the information he/she entered. anyone know how to do that?
chris
soccer362001
04-01-2003, 01:08 PM
I have the same thing on my page and my dad said that it needed cgi but i dont know how to do it. Sorry
AdamGundry
04-01-2003, 02:30 PM
You can do it client-side, by putting action="mailto:YourEmailAddress@example.com" in the <form> tag. This will display a message to the user that it is being sent, then send it using their installed email program (e.g. Outlook Express, etc.)
You can also do it server-side, using Perl, PHP, ASP, or other server-side languages, in which case you would need to find a form-to-mail script that is appropriate for your server.
Adam
chriscam19
04-01-2003, 02:50 PM
can you help me find a cgi script and help me get it working? When they click on submit I want it sent straight to my email.
soccer362001
04-01-2003, 03:36 PM
I will see what i can do
web-eagle
04-01-2003, 04:33 PM
You need a CGI script called “formmail.pl”. It’s written in Perl, and it’s available at Matt’s Script Archive (http://www.scriptarchive.com/formmail.html). I believe it’s free to use, as long as you credit the author. The instructions are included in the download. You don’t need to know Perl to use it, but there are some parameters you’ll have to set yourself, such as plugging in your e-mail address.
Check with your site host as well. Many hosts already have this script in the cgibin folder, simply because it’s so popular. You’ll probably still need to download the instructions, but you can do it. It just takes a little reading.:rolleyes:
Good luck to you.
cgraz
04-01-2003, 05:17 PM
ehhh i hate cgi. ;)
If you have PHP setup on your server, I can write a quick little loop for you to email you the results. I used to use formail.pl when I started out but I like PHP much better. ;) anyways, let me know.
Cgraz
web-eagle
04-01-2003, 05:44 PM
Cgraz, I’d like to see how it’s done in PHP, if it’s not too much trouble. Can this be done client-side without popping up the redirect warning box?
I used to program, YEARS ago (think FORTRAN, COBOL, etc.), but I haven’t decided on a 21st century language to pursue yet. These days, I mostly tweak other people’s stuff.
If you could show me an example, I could probably run with it. Thanks.
cgraz
04-01-2003, 05:57 PM
ohh man, PHP is great. anyways, below is commented code on how this would work. I used a loop, so it doesn't matter how many fields you have. It also takes the form field name, uppercases the first letter, and replaces any underscores with a space. So lets say you had
<input type="text" name="current_residence">
and the person inputted California. In your email you would get
Current residence: California
Anyways, here's the code:<?
// address the email will be sent to (change the address between quotes)
$to = "person@domain.com";
// message subject (change only what is between quotes)
$subject = "Subject Here";
// replace you@yourdomain.com with the email you want to be
// shown as the sender
$headers = "From: you@yourdomain.com";
// don't modify anything below this line
$msg = "";
foreach($_POST as $key => $value) {
$msg .= ucfirst(str_replace("_", " ", $key)) . ": " . $value . "\n";
}
mail($to, $subject, $msg, $headers);
?>Cgraz
chriscam19
04-01-2003, 06:04 PM
ok so i copy and paste that in wordpad and then lets say give it the name refer.php. ok then where do i upload it to? my cgi bin or just main directory?
chriscam19
04-01-2003, 06:11 PM
what do I put in my form so it will goto the php script you sent me. right now my form just has all the information the user needs to enter in.
cgraz
04-01-2003, 06:19 PM
sorry, forgot to mention that info. Change your form tag to look like this:
<form method="post" action="refer.php">
form contents here
then create a file refer.php (in the same directory as your form), and copy and paste the code I posted. Make any changes to the code (as far as emails and the subject line), then upload to your server.
Cgraz
chriscam19
04-01-2003, 06:48 PM
ok i have to go pay rent then I will try it when i get home. I will get back to you in an hour! thanks bro!
cgraz
04-02-2003, 02:15 PM
your problem was your form tag looked like this:
<form action="" name="Questionaire Form">
when it should've looked like this:
<form method="post" action="refer.php" name="Questionaire Form">
Go try out your form now. just fill out a few fields and click submit. Should work.
Cgraz
jeffmott
04-02-2003, 02:37 PM
You need a CGI script called “formmail.pl”. It’s written in Perl, and it’s available at Matt’s Script ArchivePlease don't recommend Matt's scripts. They are very poorly written, buggy, and insecure. Even Matt no longer recommends his scripts.
chriscam19
04-02-2003, 03:31 PM
i filled out some fields like you told me and clicked submit but after i clicked submit it takes me to a page that says:The page cannot be displayed
The page you are looking for cannot be displayed because the address is incorrect.
cgraz
04-02-2003, 03:34 PM
what's the actual url to your form? I couldn't actually test because you didn't give me your url.
Cgraz
chriscam19
04-02-2003, 03:37 PM
http://www.lsgc.info
cgraz
04-02-2003, 03:41 PM
That's cause you don't have PHP installed on your server.
Cgraz
chriscam19
04-02-2003, 03:45 PM
the lady told me I have it. ok let me call her again and get it install. be right back
chriscam19
04-02-2003, 04:03 PM
the tech guy said PHP4 is installed on my server
cgraz
04-02-2003, 04:12 PM
Ah i see. They don't accept .php extensions. They must be configured to only accept .php4 extensions.
It works fine now. I just tested (it was set to go to my email for testing purposes, but I did just get your submission). I just changed it to go to your email, so it's all up and running.
Cgraz
chriscam19
04-02-2003, 04:13 PM
i changed everything that had php to php4 and did entered some info into the fields and then clicked on submit and it said, "Submission was successful" !!!! :) so now is it going to send the info to my email account? did you tell the script to send the email to chriscam19@hotmail.com? cause I havent gotten an email yet! its been about 5 minutes!
chriscam19
04-02-2003, 04:14 PM
let me try again then
chriscam19
04-02-2003, 04:35 PM
i am still not receiving the emails, are you sure you put my email address in the form so the questionaire will get to me?
chriscam19
04-02-2003, 05:00 PM
I see you've put in my email address but I still am not getting the emails. dont give up now we are almost there :)
cgraz
04-02-2003, 06:05 PM
I have no idea. I tested it with my email and received the submissions no problem. Try registering an email other than at hotmail and see what happens.
Cgraz
chriscam19
04-02-2003, 08:36 PM
thanks it works I just changed email addresses to a yahoo address. you are the man!! you should work for NASA or something!!!! how you get so good at computers??
cgraz
04-02-2003, 08:39 PM
lets not go overboard. . .
I've been designing web sites for 4 years, doing PHP seriously for about 5 or 6 months. But it takes a lot of browsing forums and a lot of reading books and online tutorials to get there. I've still gots a ways to go. ;)
Cgraz
can you help us get the script working... we are using the same script that you supplyed to chriscam19.
<?
// address the email will be sent to (change the address between quotes)
$to = "person@domain.com";
// message subject (change only what is between quotes)
$subject = "Subject Here";
// replace you@yourdomain.com with the email you want to be
// shown as the sender
$headers = "From: you@yourdomain.com";
// don't modify anything below this line
$msg = "";
foreach($_POST as $key => $value) {
$msg .= ucfirst(str_replace("_", " ", $key)) . ": " . $value . "\n";
}
mail($to, $subject, $msg, $headers);
?>
what is happening is we click on submit and it goes to your php4 script but a blank page shows up. goto http://www.lsgc.info and click on signup. fill out some fields and click on submit. The next page will be blank and we did not get the information. we can send you the username and password so you can go into our account and fix the problem is you'd like.
cgraz
04-24-2003, 05:30 PM
well yeah, that code doesn't actually print anything to the browser, just sends an email. If you modified it and put in your email and still aren't getting anything, it may be some small difference in your php version. PM me your ftp info and tell me where the file is along with a link and I'll take a look.
Cgraz