IT Chat - News, tips, hints, ideas and freebies for people building websites or blogs

Using cgiemail to send forms via cPanel

July 14th, 2008 Posted in Building my websites

On top form!

I’ve already written about the pros and cons of different types of form already on this site, and if you get into building your own sites, you’re bound to encounter forms at some stage.

Although there many online options to get you started and help you avoid having to use HTML, the neatest way to embed forms within your site, and keep them W3C friendly if that’s what you’re trying to do, is to make them yourself.

This weekend I’ve been driven to work out how to set up forms in cPanel, mainly because I’ve been moving all of my brother’s websites from GoDaddy to nativespace.co.uk.

When I set up his megacalltelecom.co.uk website for him I made his ‘Contact us’ and ‘Apply’ forms W3C compliant, but used GoDaddy’s system to send the form data via their cgi.

I can’t use GoDaddy’s system if I’m moving hosting to nativespace.co.uk, so I was forced to tackle the cgiemail system which is administrated in cPanel.

I’ve struggled in the past to get to grips with this, but I’ve finally done it and I’m going to explain how to do it in simple steps to save you going through all the hassle I’ve had working it out.

As ever, the solution is simple … but why they don’t tell you some basic and crucial information in the instructions, I don’t know!

I’m going to assume you know how to make HTML forms in this tutorial, I’m only to going to focus on the cgiemail bit here.

Also, I’m going to assume that your cgi functions in cPanel are active and that you can see the files cgiemail and cgiecho when you look in your cgi-bin folder.

Tip: On my multi domain hosting the files cgiemail and cgiecho had only created in the cgi-bin folder in the top level domain.

I simply copied them into a new cgi-bin folder for the the domain I was using so I had them where I wanted them.

cgiemail in simple steps

1) Create your form using HTML … it will look something like this:

This is how this form looks in context on my brother’s website:

http://www.megacalltelecom.co.uk/info_pages/contact_us.htm

2) Creating the template page:

The cgiemail guide explains how to make the template page perfectly clearly, but here are a few additional tips which may avoid you scratching your head:

- Where they have written the words ‘HEADER LINES’, ‘blank lines’ and ‘BODY’ are for demo purposes only, you should remove these in your actual version

- They make a big play of making this file an ASCII file … all they mean is write it in Notepad and save it as a .txt file

- Make sure that all your labels in square brackets [ ] match exactly the the id= values in your form or it won’t work

This is what the the template file looks like for the form above:

From: [Email]
To: formsubmission@megacalltelecom.co.uk
Subject: Enquiry via megacalltelecom.co.uk website

What is your name?           [Name]
What is your country?        [Country]
What is your email address?  [Email]
Subject of your query?       [Subject]
What is your message?        [Message]

You can see the link to the actual file below … note that I have put it in a folder called ‘forms’:

http://www.megacalltelecom.co.uk/forms/contact_us.txt

3) The REALLY BIG TIME-SAVING tip

This is the bit they don’t tell you!

Why, I don’t know.

It’s only one of the most crucial bits of the entire operation … and it’s really easy.

You must make sure that cgiemail and cgiecho in your cgi-bin folder have the chmod value 0755.

That’s it!

No-one tells you in the instructions, but if you don’t do it, it won’t work.

4) The HTML bit:

Here’s the HTML that makes the form above work, which is explained perfectly well in the cgiemail guide.

Note that the id= values are all exactly the same as the square bracket [ ] values in the template file which is illustrated above:

<form action=”http://www.megacalltelecom.co.uk/cgi-bin/cgiemail/forms/contact_us.txt” method=”POST”>

<input type=”hidden” name=”subject” value=”Contact us form from megacalltelecom.co.uk” />

<input name=”Name” type=”text” id=”Name”>

<input name=”Country” type=”text” id=”Country”>

<input name=”Email” type=”text” id=”Email”>

<input name=”Subject” type=”text” id=”Subject”>

<textarea name=”Message” cols=”25″ rows=”7″ id=”Message”>

Let me break down the action= links, as this is another crucial bit of the operation:

- http://www.megacalltelecom.co.uk/ … this is your main site URL

- cgi-bin/cgiemail … this is the place where your cgiemail file is stored. To my knowledge, this will always be in the cgi-bin in cPanel

- /forms/contact_us.txt … this is where you have places your template file

5) In conclusion:

That small but crucial tip will save you hours of chasing around.

Also, I thought the example URL in the guidelines (http://web.mit.edu/bin/cgiecho/wwwdev/cgiemail/questions3.txt)
was a bit misleading, easier to go for straightforward demo URLs (http://www.megacalltelecom.co.uk/cgi-bin/cgiemail/forms/contact_us.txt)

If you’ve any more tips about how to use and set-up cgiemail, please pass them on using the comments form below.

See more cPanel posts on laptopmanpaul.co.uk

Managing your domain in cPanel

Back-ups, managing files and FTP accounts in cPanel

Managing email options in cPanel

Fantastico, php and MySQL databases in cPanel

Hidden extras in cPanel

Sorry, comments for this entry are closed at this time.