0

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>
Karl
  • 1,814
  • 1
  • 25
  • 37
Mena
  • 1,873
  • 6
  • 37
  • 77

1 Answers1

0

after I have checked the form tag of your html, I observed the following

  1. The enctype attribute that specifies how the form-data should be encoded when submitting it to the server was absent, the enctype attribute is required if method="post". this can be either multipart/form-data,text/plain, or application/x-www-form-urlencoded

  2. if this does not fix it remove the role = form and try again

Babajide Apata
  • 671
  • 6
  • 18