am trying to use PHP to send mails from a form using one page submission but i seem to be missing something since no mail is sent on submission neither does it throw up an error (which is rather weird). Below is the PHP and HTML form codes which are on the same file PHP Script
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'From: risingventures.com.ng';
$to = 'inquiry@risingventures.com.ng';
$subject = 'New message from contact form';
$body = "From: $name\n E-mail: $email\n Phone: $phone\n Message:\n $message";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers = 'From: from@example.com' . "\r\n" .
'Reply-To: reply@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $body, $headers)) {
$result = '<div class="alert alert-success">Thank You! We will be in touch with you soon</div>';
} else {
$result = '<div class="alert alert-danger">Sorry! There was an error submitting your message. Please try again</div>';
}
}
?>
HTML code
<form action="contact.php" method="POST" role="form">
<legend>Contact Us</legend>
<div class="form-group">
<div class="col-lg-12" style="margin-bottom: 20px">
<label>Name *</label>
<input type="text" class="form-control" name="name" placeholder="Please type your Firstname followed by your Lastname">
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-6">
<label>Email *</label>
<input type="email" class="form-control" name="email" placeholder="Please type in your email address *">
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-6" style="margin-bottom: 20px">
<label>Phone</label>
<input type="tel" class="form-control" name="phone" placeholder="Please type in your phone number">
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-12" style="margin-bottom: 20px">
<label>Message *</label>
<textarea class="form-control" name="message" rows="6"></textarea>
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-12" style="margin-bottom: 20px">
<input type="submit" class="btn btn-primary" value="Send Message">
</div>
</div>
<div class="form-group" style="margin-bottom: 20px">
<div class="col-lg-12" style="margin-bottom: 10px">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
</div>
</form>