0

I'm not able to find the error in my code. My PHP code is in my index.html file. I'm not able to send messages from my static webpage.

HTML Code:

<div class="col-md-6">
    <form action="index.html" method="POST" class="contact-form" role="form">
        <input type="text" class="form-control" id="fname" name="fname" placeholder="Your Full Name">
        <input type="email" class="form-control" id="email" name="email" placeholder="Your E-mail">
        <input type="text" class="form-control" id="subj" name="subj" placeholder="Your Subject">
        <textarea id="mssg" name="mssg" placeholder="Your Message" class="form-control" rows="10"></textarea>
        <input class="btn btn-main btn-lg" type="submit" id="submit" name="submit" data-loading-text="<i class='fa fa-spinner fa-spin'></i> Sending...">
    </form>
</div>

PHP Code:

<?php

if (isset($_POST['submit'])) {

    $to = 'email@company.com';
    $siteName = 'http://www.website.com';
    $name = $_POST['fname'];
    $mail = $_POST['email'];
    $subject = $_POST['subj'];
    $message = $_POST['mssg'];
    $mailSub = '[Contact] [' . $siteName . '] '.$subject;

    $body = 'Sender Name: ' . $name . "\n\n";
    $body .= 'Sender Mail: ' . $mail . "\n\n";
    $body .= 'Message Subject: ' . $subject . "\n\n";
    $body .= 'Message: ' . $message;

    $header = 'From: ' . $mail . "\r\n";
    $header .= 'To:  ' . $to . "\r\n";

    mail($to, $mailSub, $body, $header);
}else{
    echo '0';
}
?>

I receive an error every time i try to send a message through my website. Thank you!

  • 1
    " I receive an error every time i try to send a message through my website" what error? –  Aug 15 '16 at 03:27
  • `action="index.html"` did you instruct your system to handle `.html` files as PHP? If not, then *"Houston, we have a problem"*. – Funk Forty Niner Aug 15 '16 at 11:24

1 Answers1

2

Looking at action="index.html" could be a problem if you did not instruct your system to treat .html files as PHP.

If not, then you will need to change it to a .php file extension and renaming your present file to accomodate it. Then change your action value to direct to that file.

For example:

<form action="script.php" method="post">

  • script.php being your present PHP handler.
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141