After having learned PHP recently, I am trying to implement my studies in a project.
I am in creating an extremely simple contact form (no validation for now) but it doesnt seem to be working in terms of sending the email.
Now I know that in order for this to work it needs to be uploaded to a server and I do so using netlify.
I have replaced the original email address with a dummy one for privacy reasons.
HTML:
<form class="joinContactForm" action="main.php" method="post">
<div class="flexFormRow">
<label class="formLabel" for="name">Your Name:</label> <input class="formInput" type="text" name="name" id="name"/>
</div>
<div class="flexFormRow">
<label class="formLabel" for="email">Your Email:</label> <input class="formInput" type="text" name="email" id="email"/>
</div>
<div class="flexFormRow">
<label class="formLabel" for="number">Phone Number:</label> <input class="formInput" type="text" name="number" id="number"/>
</div>
<div class="flexFormRow">
<label class="formLabel" for="age">Age:</label> <input class="formInput" type="text" name="age" id="age"/>
</div>
<div class="flexFormRow">
<span class="formLabel2">Address:</span> <textarea name="address" id="address" class="addressText"> </textarea>
</div>
<div class="flexFormRow">
<label class="formLabel" for="postcode">Postcode:</label> <input class="formInput" type="text" name="postcode" id="postcode"/>
</div>
<div class="flexFormRow">
<span class="formLabel2" for="comments">Comments:</span> <textarea id="comments" name="comments" class="addressText"> </textarea>
</div>
<div class="flexFormRow">
<span class="formLabel2"></span><button type="submit" id="submit" name="submit" class="submitForm">SUBMIT</button>
</div>
</form>
PHP:
<?php
if (isset($_POST["submit"])){
$name = $_POST["name"];
$email = $_POST["email"];
$number = $_POST["number"];
$age = $_POST["age"];
$address = $_POST["address"];
$postcode = $_POST["postcode"];
$comments = $_POST["comments"];
$mailTo = "example@hotmail.co.uk";
$mailFrom = "From ".$email;
$mailText = "You have received an email from ".$name.".\n\n".$comments;
mail($mailTo, $mailFrom, $mailText);
}
?>
Thanks for the help!