Jump to content

Trying To Test A Php Form


Xyth

Recommended Posts

Hello,

 

Firstly I should say that I have very little to no experience at all of coding PHP or any sort of web development really.

 

That said I am trying to set up a simple PHP form so that, eventually, people will be able to visit a website I am in the process of designing, fill in a form with some details which I can then retrieve via email easily. Seems to me this shouldn't be too difficult, right?

 

At the moment I am just working from some example code I have found on various pages online, editing it in Notepad before making final layout adjustments in ExpressionWeb... I see no particular problem with this but please, if there is one, please point it out.

 

I would be very open to any suggestions on simple, WYSIWYG PHP form editors that I could use to speed up this process...

 

 

So far I have come up with 2 files - form.php and senddetails.php - I have put the code for both files below:

 

<html></html><form enctype="multipart/form-data" method="post" action="senddetails.php">
<div style="text-align: center">
<input type="hidden" name="required_vars" id="required_vars" value="name,email">
</div>

<table cellspacing="5" cellpadding="5" border="0" align="center">
<tr>
<td valign="top" style="text-align: center">
<strong>Your Name:</strong>
</td>
<td valign="top">
<input type="text" name="name" id="name" size="40" value="">

</td>
</tr>

<tr>
<td valign="top" style="text-align: center">
<strong>Address line 1:</strong>
</td>
<td valign="top">
<input type="text" name="address1" id="address1" size="40" value="">

</td>
</tr>

<tr>
<td valign="top" style="text-align: center">
<strong>Address line 2:</strong>
</td>
<td valign="top">
<input type="text" name="address2" id="address2" size="40" value="">
</td>
</tr>

<tr>
<td valign="top" style="text-align: center">
<strong>Town:</strong>
</td>
<td valign="top">
<input type="text" name="town" id="town" size="40" value="">

</td>
</tr>

<tr>
<td valign="top" style="text-align: center">
<strong>County or State:</strong>
</td>
<td valign="top">
<input type="text" name="countystate" id="countystate" size="40" value="">
</td>
</tr>

<tr>
<td valign="top" style="text-align: center">
<strong>Postcode:</strong>
</td>
<td valign="top">
<input type="text" name="postcode" id="postcode" size="40" value="">
</td>
</tr>

<tr>
<td valign="top" style="text-align: center">
<strong>Message:</strong>
</td>
<td valign="top">
<textarea name="persmes" id="persmes" rows="6" cols="40"></textarea>
</td>
</tr>

<tr>
<td valign="top" style="text-align: center">
<strong>Your email address:</strong>
</td>
<td valign="top">
<input type="text" name="email" id="email" size="40" value="">
</td>
</tr>

<tr>
<td colspan="2" style="text-align: center">
<input type="submit" value=" Submit Form ">
</td>
</tr>
</table>
</form></HTML>

 

<?php
$ToEmail = 'postmaster@localhost';
$EmailSubject = 'Details';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY = "Address Line 1: ".$_POST["add1"]."";
$MESSAGE_BODY = "Address Line 2: ".$_POST["add2"]."";
$MESSAGE_BODY = "Town name: ".$_POST["town"]."";
$MESSAGE_BODY = "County/state: ".$_POST["countystate"]."";
$MESSAGE_BODY = "Postcode: ".$_POST["date"]."";
$MESSAGE_BODY = "Message: ".$_POST["persmes"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>

 

 

This looks fine to me but as I said I don't really know anything about PHP so I could be way off.

 

To view the first one I have to either put <HTML> tags around the code or rename it to form.html, I assume this is normal.

 

I understand that in order to test this locally I have to install a local PHP server and mail server. I have installed first ArGosoft Mail Server, and then XAMPP, but honestly I just have no idea where to go from here. (Obviously I am not running them at the same time, I have stopped running the ArGosoft server once I realised I needed more than just a mail server to test this PHP script).

 

What frustrates me is that seemingly no matter what I do, when I click that "Submit Form" button in my browser I just get the plain text code of form.php thrown up in front of me. I have XAMPP running with Apache, MySQL and Mercury running but still my computer refuses to run senddetails.php.

 

Surely there should just be a simple way to set up a local test environment for this sort of thing?!

 

 

I apologise as I realise I may be asking a lot, given my limited knowledge I am almost asking to be spoonfed here but I would really appreciate any help that anyone can give. Thanks in advance.

 

Oh yeah I should probably also add I am trying to test this out on a Windows 7 machine.

Edited by Xyth
Link to comment
Share on other sites

Woops, I didn't realise I couldn't just open the PHP files directly in my browser. Have now moved them both to C:\xampp\htdocs and accessed the form through http://localhost/form.php.

 

However, I'm guessing there must be something wrong with senddetails.php (I realise there are some small mistakes in the code I posted above relating to the ID of some of the fields - I have since corrected these).

 

I've disabled Mercury in XAMPP for now and gone back to using ArGo Mail Server because I'd already configured this with Thunderbird but can't work out how to do the same with Mercury. Nonetheless I press "Submit Form" and my inbox remains empty?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.