Setting Up Local Host for Website Testing

If you have been trying to set up a feedback form using a php script and everything looks to be going really well until you get to the moment of truth, you click on submit the form and you get:

Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set()..

This is where the nightmare begins, you can trawl through endless forums and search for the solution to the problem and you will find string after string of posts from people who have experienced the same problem with nearly as many proposed solutions.

I have actually managed to get a working solution, but before you get excited let me explain exactly what I am doing so that you can assess whether this solution can potentially work for you.

First, I wanted a reliable feedback form for a website I am designing. I use the Windows operating environment and wanted a php script that would deal with the information being submitted from a .html page and forward it to the required email address, simple as that.

Next I wanted to set up a local web server so that I could change the default script that I had got hold of and test it on my own PC before going live. I decided to use Apache with .php for my test environment running on Windows XP.

So first thing you need to do is ensure that the host supports .php scripting, not all of them do. If your host does not support php you are on a looser from the start and will have to consider using java scripts or Perl as an alternative neither of which are included in this post.

For a basic .php feedback form you should visit The Site Wizard, this guy is a wizard as far as I am concerned. I used his feedback form generator wizard and had a working solution straight away.

Problem was that his form was not exactly what I wanted, I needed a couple of extra features and to change the layout a little. I noticed that he had instructions for setting up a localhost using Apache and .php. That way I could copy the website files to my localhost.com domain (which I would set up on my PC) and test any configuration changes before going live, sounded perfect.

I followed the instructions to the letter and in no time at all I had Apache and .php running on my local machine. Duly copied the files across to the domain directory loaded the contactus html page onto the browser and clicked on the submit button.

That’s when I got the dreaded error message and the trouble started, I was trying to use the gmail smtp server to send out the form information to the target email address.

In the end I found a solution when I discovered Digiex Feed Your Mind who offered a ‘sendmail’ fake email solution.

The problem I had was that I had no email server on my machine so when I tried to use my gmail smtp to send the mail it simply didn’t work, the reason being that you have to authenticate your logon, the pop and smtp are encrypted and the port numbers are different to the default number 25.

With sendmail you have a middle man that sits between the form and your email provider, logs onto your server for you and deals with the security issues because you can include your user name, password and select a port to match the server. The solution is supposed to work with gmail which is what I was using, so again it seemed perfect.

When I employed the recommended solution using sendmail, I no longer got the dreaded error message and instead got my ‘thankyou’ message your enquiry has been submitted.

Eureka, I am there (3 days later I’ll have you know). Anyway I was a bit premature because, you guessed it, the email didn’t arrive.

After trying numerous combination’s for configuring the php.ini and the sendmail.ini to get the system to work with gmail, I decided that I would look for an alternative email provider and I selected gmx.com.

This is a good quality free email service that you can access with Outlook using their pop3 server and smtp options. The interesting thing about gmx is that they do not use the encrypted pop and smtp check boxes and the smtp port is 25, so they had to be worth a shot.

I had to change the SMTP option to mail.gmx.com and set the port to 25 rather than one of the encrypted ports. The rest I just followed the instructions given including the commenting out of the SMTP mail handler lines in php.ini and the adoption of using the linux ‘sendmail_path’ option as described in the Digiex dialogue.

This time it was hey presto and it really was EUREKA because the form was submitted and the email duly arrived about 60 seconds later.

So if you are struggling with this one and are happy to adopt the same method as I used then your troubles are over.

Happy feedback forms to you.

In summary: –

  • Use The Site Wizards php feedback form generator wizard to create a basic form.
  • Use The Site Wizards instructions for downloading and installing Apache and .php to create a localhost server on your own PC so you can test any new configurations
  • USe the Digiex instructions for setting up and configuring the sendmail option if you don’t have an email server on your PC
  • Register and adopt gmx.com’s free email service as an alternative to gmail if you cannot get gmail to work with sendmail
  • Use The Site Wizards .php tutorials for editing your .php script and html form to change the form configurations as required
  • Test any new configurations on your newly working localhost webserver.
  • I used php 5.2.8 and Apache 2.2.10

Hope this helps and if I have not been clear give me a shout and I will try and clarify.

This entry was posted in website design. Bookmark the permalink.

One Response to Setting Up Local Host for Website Testing

  1. Kikolani | Blogging, Poetry, Photography says:

    Where was this article when I was at my last job. Our marketing person wanted a test site hooked up to her Dreamweaver, and I never got it running. Very informative post for next time.

    ~ Kristi

Leave a Reply