Jump to content

Insert contact Page PHP file in html.


jacob_1988

Recommended Posts

I have a designed a small webpage which also has a 'contact me' selection but I cannot seem to send/receive any message from my webpage? Moreover, how do I insert the correct code to make my php (contact page) file run correctly?

HTML Form Code:

<form class="form-horizontal" role="form" action="index.php" method="POST">
                         <div class="form-group row">
                      <label for="name" class="col-2 col-form-label">Name</label>
                  <div class="col-8">
                <input type="text" class="form-control" type="text" id="name" name="name" placeholder="First and Last Name" value="">
                  </div>
                </div>
              <div class="form-group row">
                  <label for="email" class="col-2 col-form-label">eMail</label>
                      <div class="col-8">
                        <input type="email" class="form-control" type="text" id="email" name="email" placeholder="example@domain.com" value="">
                              </div>
                            </div>
                       <div class="form-group row">
                          <label for="message" class="col-2 col-form-label">Message</label>
                              <div class="col-8">
                                  <textarea class="form-control" row="4" name="message"></textarea>
                                      </div>
                                    </div>
                        <div class="form-group row">
                            <label for="human" class="col-2 col-form-label">2 + 3 = ?</label>
                                <div class="col-8">
                                    <input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
                                        </div>
                                    </div>
                        <div class="form-group row">
                            <div class="col-6 offset-sm-2">
                                <input id="submit" name="submit" type="submit"  value="Send Message!" class="btn-message btn-lg">
                                  </div>
                                </div>
                            </form>

 

PHP FORM Code:

<?php

if($_POST['robots'] != '') {
echo 'No spammers here!';
} else {
// Process the the form
}

$to = 'xxxx.com';
$subject = 'info help ';
$message = 'From: ' . $_POST['name'] . "\n";
$message .= 'Email from: ' . $_POST['email'] . "\n";
$message .= "Message:\n" . $_POST['Message'] . "\n\n";
$headers .= 'Cc: admin@xxxxx.com';
mail($to, $subject, $message, $headers);


mail ($email, $subject, $message, "from:".$from);

header('Location: index.html');
exit();

?>

 

Link to comment
Share on other sites

I actually got the file to send a small email but it contains no message? I'm now having to sort the 'undefined index: robot', 'undefined index: Message' and the undefined variables headers, email and from.

The full line of the index.php is the web address plus the php file (as below.)

<form class="form-horizontal" role="form" action="https://xxxxxx.000webhostapp.com/home/xxxxxx/index.php" method="POST">

Link to comment
Share on other sites

I changed the 'Message' wording to the correct case-sensitive word 'message' - this made the program print a message. I'm still getting undefined variable with 'email' and 'from' line 18.

Line 18: $email, $subject, $message, "from:".$from);

Link to comment
Share on other sites

What can I do regarding the code (as below?) I keep getting the message 'undefined index: robots' on line 3. Moreover, I wanted the code to guard my site against spammers.

if($_POST['robots'] != '') {
echo 'No spammers here!';
} else {
// Process the the form
}

Link to comment
Share on other sites

That means a post index name of 'robots' does not exist to compare the value in if condition.

The index name must exist on form submission, it must match exactly the value used for name attribute used for each input, as 'Message' and 'message' are treated as different index values.

Edited by dsonesuk
Link to comment
Share on other sites

Think about it! if an non existent post name that it is used in an if condition does not exist do you

(A) Provide a input with name attribute value of 'robots'

(B) Keep as it is resulting in the same error.

(C) Hope it will magically correct itself.

if

name="name"

name="email"

name="human"

did not exist on the inputs using these on submission, you would be getting the same error for each.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...