-4

Recently I want to make basic contact form. I get stucked.. I have 3 files: contact.php form.php and style.css

contact.php:

    <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="style.css">
  <title></title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
</head>
<body>
  <section>
    <article>
      <div class="container">
        <form id="contact" action="form.php" method="post">
          <h3>Contact</h3>
          <h4>Contact us today, and get reply with in 24 hours!</h4>
          <fieldset>
            <input type="text" name="name" placeholder="Your name">
          </fieldset>
          <fieldset>
            <input type="text" name="mail" placeholder="Your Email Address">
          </fieldset>
          <fieldset>
            <input type="text" name="site" placeholder="Your Web Site starts with http://">
          </fieldset>
          <fieldset>
            <textarea name="message" placeholder="Type your Message Here...." ></textarea>
          </fieldset>
          <fieldset>
            <button type="submit" name="submit" >Submit</button>
          </fieldset>
        </form>
      </div>
    </article>
  </section>
</body>
</html>

form.php

<<?php 

if (isset($_POST['submit'])) {
  $name = $_POST['name'];
  $mail = $_POST['mail'];
  $site = $_POST['site'];
  $message = $_POST['message'];


  $mailTo = "info@example.co";
  $headers = "From: ".$mail;
  $txt = "You have received an e-mail from email".$name.".\n\n".$message;

  mail($mailTo, $name, $txt, $headers, );
  header("Location: contact.php?mailsend");
}

style.css isn't important because it was working. Whats wrong with my code? I put files on my server on my site and I get error prompt. " HTTP ERROR 500 "

Thanks for help.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

-2

You have the following:

<<?php 

This means that a < will be output to the browser. Once output has started (HTTP request body), then HTTP headers can no longer be sent.

Remove that, and the header call should work.

Also, there is an extra comma in the mail call. Remove that too.

mail($mailTo, $name, $txt, $headers, );

Always check your error_log! It tells you which exact line caused your error!

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39
  • 1
    I remove a one `<` and extra comma. And script working I get `contact.php?mailsend` but I didn't receive the message on my email. I checked and I entered correct email address. – Maciej Wiśniewski Jul 19 '18 at 11:44
  • Check your `sendmail_path` setting in php.ini, make sure it is configured correctly. Also double check it hasn't been moved to spam. – delboy1978uk Jul 19 '18 at 11:48