View Full Version : Wanted a cgi script for a web form.
Viking warrior
12-05-2011, 11:38 AM
I have coded several html5 web forms, but in html the "submit" button produces an email which then has to be sent manually, displaying the email address in the process. I need a script that submits the form directly to the intended recipient without the intervening email problem. Suggestions, please.:confused:
djr33
12-05-2011, 02:39 PM
Instead of using your email as the "to" field for the mail() function in PHP, or in your other form mailer (such as an external service), you will need to set the user's email as the "to" field. However, you may also want to verify the address so that you don't attempt to send messages to invalid addresses, and potentially to avoid sending lots of spam.
Using PHP (or another serverside language) will give you the most control. There are plenty of tutorials out there about this, at least for PHP.
If you need more help, I'd suggest first looking for a tutorial, but if you need specific help with what you're already using, then you should post the code you have.
Viking warrior
12-05-2011, 03:39 PM
Thanks for your reply Daniel. I'm sure there are thousands of people who would have understood it - unfortunately, I'm not one of them! If php stands for pretty hopeless plonker I'm your man. It seems to me that if I put the user's email address in the mailto bit, the form would be submitted to him, not the person who wants it. Have I misunderstood something?
An example:
<form method="post" action="mailto:lasmoneyman@gmail.com" enctype="text/plain">
<p class="layout17">Full name <input type="text" name="fullname" size="40" /></p>
<p class="layout17">Address 1 <input type="text" name="street" size="40" /></p>
<p class="layout17">Address 2 <input type="text" name="district" size="40" /></p>
<p class="layout17">Town/city <input type="text" name="city" size="40" /></p>
<p class="layout17">County <input type="text" name="county" size="40" /></p>
<p class="layout17">Post Code <input type="text" name="postcode" size="40" /></p>
<p class="layout17">Country <input type="text" name="country" size="40" /></p>
<p class="layout17">Telephone No <input type="text" name="tel" size="40" /></p>
<p class="layout17">Mobile No <input type="text" name="mob" size="40" /></p>
<p class="layout17">email address <input type="text" name="email" size="40" /></p>
<p><textarea name="comments" rows="4" cols="100" class="formtext">Please include here any information, comments or requests which you think will be of interest to the Society.</textarea></p>
<p><input type="reset" class="formtext" value="Press here to clear the form" /><input type="submit" class="formtext" value="Press here to submit" /></p>
</form>
What needs to be added or changed to make the "submit" button send the form direct to the addressee - is "mailto:" not the right code?
Sorry to be a pain.
djr33
12-06-2011, 09:05 AM
I misunderstood your other post. I thought you were referring to a situation where you received an email then needed to manually forward it to the final recipient.
Here's a summary of how sending emails using a form can work, from one of my earlier posts (in another thread):
1. Use action="mailto:e@mail.com" -- worst but easiest option. It requires the user send an email to you based on the form. Won't work in many cases and not professional.
2. Use a "free form mailer" (google that). That will give you a page to send the data (through the action) and send out an email from it.
3. Use/learn PHP and write a form script yourself. It certainly isn't impossible, but you do need to learn some PHP scripting.
If you use option (1), as you are currently doing, then you can't control it at all. Basically it's just a way to suggest to the user's computer that they send an email to you. Nothing more, and for many users it won't work at all (for example, if they use webmail of some sort, such as hotmail or gmail). It's really best to avoid it, although it is a little tempting because it's so easy.
(2) is a good option because it doesn't require any complex setup-- another company does that for you. But it will result in ads for the submitter, and sometimes in the message too. But if you don't mind that and can find one that submits in a good format, it's a good option.
If you don't want to learn to send emails from your server yourself, a free form mailer is a nice tool. But I recommend it only if you are the only recipient-- receiving slightly ugly emails (default formatting, sometimes with technical info or ads) isn't a problem for you (maybe annoying, but not a problem), but it would be unprofessional and maybe confusing for others. So avoid that if you can.
The way this works means that the users will end up at the free form mailer website, so if that page is ugly, they'll see it-- best to find one with a friendly page, and potentially a link back to your site.
(3) is by far the best option and you can do anything you want with it, silently send the email, format the email as you want (and send a copy to yourself and/or the user), and the user stays on your site the whole time. But it's hard to set up.
There are two things to know:
1-- you don't need to use PHP. Any server-side programming language (like PHP, ASP, CGI, and others) will work fine. PHP is just the most common and in many cases you will have that available on your server. Find out what your server has available (and potentially what you'd want to learn for other reasons) and use that. If you have nothing available (on a free or low quality host), it's probably time to upgrade-- about $5/mo will get you PHP, and probably a database as well if you'd ever want that. Lots of hosts have plans like that, just look around.
2-- Although this option gives you complete control, the slightly easier option is to use an existing script. It works the same way, but you just use that script rather than making your own. It's a little easier (although doesn't give you control over all the details). Also, some hosts actually do have form mailers of some sort configured. Check with your host to see if anything is available and how to use it.
Viking warrior
12-06-2011, 02:33 PM
Hi Daniel: Thanks for your message, which is very helpful. Unfortunately my webhost (1and1) does not provide this level of cgi scripting in my package (£60 pa, which is all I can afford). Their response to my request was to direct me to http://nms-cgi.sourceforge.net/scripts.shtml, which may be a good source but apparently requires me to re-configure it after down-loading, which I was hoping to avoid. Hence my request to DD. Do you have an opinion about this source, please?
djr33
12-06-2011, 09:20 PM
Many hosts have a specific way to create a contact form. Sometimes it's called an "add-on" or "application", and other times it is done through using a default form mailer-- basically it's a script already setup on the server and you can send it information from a form (information to send in an email, and information about how to send that email).
If you don't have that, you can still make a contact form using PHP (or another serverside language). It just means that you'll have to do it yourself.
You can use an existing script from somewhere (there are lots of them). The one you linked to is probably fine. If you can use CGI on your host, then it's an option. Personally I prefer PHP simply because I use PHP so it's easier in that way.
Or you can actually write the code yourself. Honestly it's not that hard and once you've done it a few times it's probably faster than configuring a prewritten script. It's certainly an advanced way to do it, but if you have enough time to figure it out, it's a good option.
I use 1&1, and all of their plans allow php's mail() function.
Search for some tutorials and give one a try, then you can post here again if you need help with something specific.
Viking warrior
12-07-2011, 05:23 PM
Hi guys:
Thankyou for your help. First stop is to try the 1and1 php route. I will report back (probably in 2013:)). Thanks again.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.