# PHP contact form with JavaScript submit

**URL:** <https://forum.kirupa.com/t/php-contact-form-with-javascript-submit/319760>\
**Category:** Uncategorized\
**Created:** [March 3, 2011, 5:03pm UTC](https://forum.kirupa.com/t/php-contact-form-with-javascript-submit/319760 "2011-03-03T17:03:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaleCooper](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@DaleCooper](https://forum.kirupa.com/u/DaleCooper)\
**Post date:** [March 3, 2011, 5:03pm UTC](https://forum.kirupa.com/t/php-contact-form-with-javascript-submit/319760/1 "2011-03-03T17:03:35Z")

</div>

I can get the form to recognize the PHP file, but I keep getting the error message when using the JavaScript submit link. If it’s just a regular input submit button everything works. Am I missing some JavaScript or PHP code? Any help would be appreciated. Thanks!

HTML

```auto
<form action="sendform.php" id="form1" name="form1" method="post">
        <fieldset>
          <label>Enter Your Name:
            <input id="name" name="name" type="text">
          </label>
          <label>Enter Your Email:
            <input id="email" name="email" type="email">
          </label>
          <label id="message" name="message" class="txt">Enter Your Message:
          <textarea></textarea>
          </label>
          <span class="btns">
              <a href="javascript:document.getElementById('form1').reset()" class="mrk">Reset</a>
            <a href="javascript:document.getElementById('form1').submit()" class="mrk">Submit</a>
            
          </span>
        </fieldset>
      </form>

```

PHP

```auto
<?php
if( isset( $_POST['submit'] ) || isset( $_POST['submit_x'] ) ) {

    $to = "email@email.com"; 
    $subject = "Contact Form";
  $name = $_POST['name'] ;
  $email = $_POST['email'] ;
  $message = $_POST['message'] ;
  
  

    
    $body = "
  Name: $name

  Email: $email

  Message: $message

  
  ";

    echo "Your information has been submitted. An associate will contact you shortly.";
    mail($to, $subject, $body);
    
} else {
    echo "We're sorry but your form could not be sent at this time.";
}
?>

```
