-4

again i trying to do a simple contact form for sending email,

thats the code:

<?php

if (empty($_POST) === false) {
   $errors = array();

   $name     = $_POST['name'];
   $email    = $_POST['email'];
   $message  = $_POST['message'];

   echo $name,' ', $email, ' ', $message;

   if (empty($name) === true || empty($email) === true || empty($message) === true) {
    $errors[] = 'name,email and message are required';

   } else{
     if(filter_var($email,FILTER_VALIDATE_EMAIL) === false){
        $errors[] = 'that\'s not a valid email address';

     }
      if(ctype_alpha($name) === false) {

       $errors ='name must only contain letters';
      }
}

if (empty($errors) ===true) {


 mail('talrod160@gmail.com','contact form','$message','From:' . $email);
 header('location:index.php?sent');
 exit();


}

?>

<!DOCTYPE html>
<html>
 <head>
  <title>A contact form</title>
 </head>
    <body>
    <?php
    if (isset($GET ['sent']) === true) {
     echo '<p>Thanks for contact us<?/p>';
   
    } else {


     if (empty($errors) === false) {
          echo '<ul>';
          foreach($errors as $error) {
            echo '<li>', $error, '</li>';
          }
           echo '</ul>';

     }

     ?>

     <form action="" method="post">
          <p>
            <label for="name">Name:</label><br>
            <input type="text" name="name" id="name" <?php if (isset($_POST['name']) === true){echo ($_POST['name']), '"'} ?>>
         </p>

         <p>
            <label for="email">Email:</label><br>
            <input type="text" name="email" id="email"<?php if (isset($_POST['email']) === true){echo 'value="', ($_POST['email']), '"'} ?>>
        </p>


         <p>
            <label for="message">Message:</label><br>
            <textarea name="message" id="message"><?php if (isset($_POST['message']) === true) { echo strip_tags ($_POST['message']); } ?></textarea>
        </p>

        <p>
        <input type="submit" value="Submit">
       </p>
        </form>
        <?php
         }
        ?>        

    </body>

</html>

now i get this problem and cant understand why,

Parse error: syntax error, unexpected '<' in D:\xampp\htdocs\contact_form\index.php on line 46

and would like if someone can explain me me about foreach loop

thanks.

marvelX
  • 19
  • 5
  • 1
    In the future, if you're going to provide a line number in your question (which you should) you should also indicate what the content of that line is, as we can't see any line numbers. – Tim Lewis May 21 '15 at 18:20
  • yep sorry! - now its in line 65 and the line is : > – marvelX May 21 '15 at 18:28
  • Try a `ternary ?` operator: ` />` Best used for inline `if` statements. That or concatenate property: `$_POST["name"].'"'`, not `$_POST["name"], '"'`. – Tim Lewis May 21 '15 at 18:42

1 Answers1

1

<p>Thanks for contact us<?/p> probably should be <p>Thanks for contact us</p>

Josep Valls
  • 5,483
  • 2
  • 33
  • 67