I'm trying to setup a contact form on a website I'm working on, the code for which looks like this:
<form action="contact.php" method="POST">
<ul>
<li>
<label for="name">Name:</label><br>
<input type="text" name="name" />
</li>
<br>
<li>
<label for="email">E-mail:</label><br>
<input type="email" name="email" />
</li>
<br>
<li>
<div id="label">Enquiry:</div>
<select name="interest"><br>
<option value="Wedding">Wedding</option>
<option value="Engagement/Couple">Engagement or Couple</option>
<option value="Portrait">Portrait</option>
<option value="Family">Family</option>
<option value="Children">Children</option>
</select>
</li>
<br>
<li>
<label for="message">Message:</label><br>
<textarea name="message" cols="40" rows="6"></textarea>
</li>
<br>
<li>
<button class="submit" type="submit" value="Submit">Submit Form</button>
</li>
</ul>
</form>
Originally I just had the form action as a mailto:myemail@example.com but I would obviously prefer for the user to just submit the form and the email be sent instead of just opening their email application. I'm trying to build a PHP script to do this but am having no luck as yet, probably because this is my first time ever even looking at PHP, let alone trying to write it.
I have looked at many different examples and delved into the PHP manual for help but whatever I write leads to the same result, pressing the submit button on my form and receiving nothing in my inbox. So I started a sort of fault finding process to try and help determine the problem. I would start with really basic PHP scripts and then try and add more to each one and see where it broke.
I started by changing the form action to the php test script as below:
<?php
phpinfo() ;
?>
This worked fine and displayed the php info page as it should. Great so I know that my host supports php and has it installed. This is not the problem then. Second I changed the form action to this code below:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
And again it worked as expected showing the Hello World paragraph. After this I attempted the most basic php mail script I could think of which looked like this:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
mail('myemail@example.com', 'Contact Form', 'This is a test');
?>
</body>
</html>
All this succeeds in doing when I press the submit button on my form is displaying a blank page with the url of my php script in the address bar of my browser and from this I have received no email. Not in my inbox or junk folder, nowhere. As this is such a simple script I have two trains of thought at the min. 1 is that I'm just doing something very basic wrong, which is a high possibility considering my extremely limited knowledge of php. 2 is that something more complicated is going on, maybe php settings of my host are not correct for what I'm attempting to do? I don't know.
I apologise for this question being so long winded, I just wanted to show what I'd done so far in the hope that it will help you guys with any assistance you can give me. Any help with my problem is greatly appreciated, thank you.