I am trying to send an email from a webpage but when i click on the submit button php code is opening. I have installed apache server and its up and running. I am not quite sure what i am missing and how to send an email from webpage. do i need to install sendmail and php also to make it work in local using apache server. below is my code. please help
<form action= "temp.php" method="post" name="sentMessage" id="contact" >
<div class="row">
<div class="col-md-6" style="margin-left:-5px;">
<div class="input-field">
<input type="text" name="name" class="form-control" id="name"
required
data-validation-required-message="Please enter your name" />
<label for="name" class=""> Name </label>
<p class="help-block"></p>
</div>
</div>
</div>
<!-- For success/fail messages -->
<button name="submit" type="submit"
class="btn btn-primary waves-effect waves-dark pull-right">Send</button>
<br />
</form>
and php code is as follows.
<?php
if(isset($_POST['submit'])){
$to = "xyz@gmail.com"; // this is your Email address
$from = "abc@gmail.com"; // this is the sender's Email address
$subject = "Form submission";
$message = "form submission";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
echo "Mail Sent";
}
?>