Contact form not working

I have been tampering with the contact form for many hours but it still does not work. Unfortunately, I have no knowledge of PHP.
Can you please be so good to correct the contact form?

Also very important: I do not want the textbox “username” to be present. Please remove it.

Very many thanks in advance!
PS: Hopingly, I have inserted the codes OK for.

<form action="mail.php" method="POST">
				    <div class="row">
				        <div class="col-md-6">
				            <div class="form-group">
				                <label for="email">Email address</label>
				                <input type="email" class="form-control" id="email" placeholder="Enter email">
				        <div class="col-md-6">
				            <div class="form-group">
				                <label for="username">Username</label>
				                <input type="name" class="form-control" id="username" placeholder="Name">
				    <div class="form-group">
				        <label for="message">Message</label>
				        <textarea class="form-control" rows="3"></textarea>
				    <button type="submit" class="btn tf-btn btn-default">Submit</button>

         $to = "";
         $subject = "Email from ".$_POST['username'];
         $message = $_POST['message'];
         $header = "From:".$_POST['email']." \r\n"; 
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";
         $retval = mail ($to,$subject,$message,$header);
         if( $retval == true ) {
            echo "Message sent successfully...";
         }else {
            echo "Message could not be sent...";

Your input form fields do not have the name attribute which they need. The id attribute is for the label, it does not name the input in the $_POST array.

<input name="email" type="email" class="form-control" id="email" placeholder="Enter email">

Add a name attribute to each input.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.