How to Test a PHP Contact Form in XAMPP

Written by sara williams
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Test a PHP Contact Form in XAMPP
Turn on Mercury Mail in XAMPP to test your contact forms. (Photodisc/Photodisc/Getty Images)

Novice PHP programmers and pros both use XAMPP as a way to test scripts on their own computers before making changes to websites on live servers. XAMPP comes with the "LAMP stack" (Linux, Apache, MySQL and PHP) without the need to run on Linux, though it can. You can install it on both Windows and Mac computers. XAMPP lets you test PHP on your computer, but programmers may get into trouble when testing contact forms that require a mail server. Turning on Mercury Mail in XAMPP will solve this problem.

Skill level:
Moderate

Other People Are Reading

Instructions

  1. 1

    Click "Start" and type "XAMPP" into the search box. Select "XAMPP Control Panel" and press "Enter" to load the program. Click "Start" next to both "Apache" and "Mercury" to get the Web server and Mail server running. You need both to test PHP forms in XAMPP.

  2. 2

    Open your PHP form in a code editor or in Notepad. Find the first form tag and look at its action attribute:

    <form method="post" action="processform.php">

    If the action is equal to the same name as the PHP contact form file you opened, then you need to edit that file. Open the file specified as the action for the form. You may already have the correct file opened if the action's file name matches the contact form's file name.

  3. 3

    Locate the part of the code that specifies where the form will be sent. Often, this is assigned to a variable called "$to," but you can find the variable's name in the first variable listed in the "mail()" function.

  4. 4

    Change the email address to "admin@localhost" and save your file. XAMPP gives this e-mail address to you for testing with its Mercury Mail server.

  5. 5

    Open a Chrome or Firefox browser with the "Web Developer" and "Firebug" add-ons installed. Go to your contact form and fill out the fields. Type "send" and see what the form does. You can add this code to your form handling PHP code to generate test messages:

    if(mail($to, $subject, $comment, $headers)) {

    echo '<p>Hey, it went through! Thanks, ' . $_POST['name'] . '.</p>';

    } else {

    echo '<p>Ooops! Didn't work.</p>';

    }

Tips and warnings

  • Type "localhost" into your browser and click on the "Mercury Mail" link on the left menu to find out more about what Mercury Mail can do.
  • Work in a code editor with line numbers and coloured code for best results. PHP errors will tell you which line of code to fix, and counting lines of code in Notepad is a tedious task.

Don't Miss

References

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.