简体   繁体   中英

simple PHP contact form returns 500 internal server error

Im trying to implement a simple form for visitors to contact me by. Im using php (Im a very beginner) and am having problems that it is returning 500 internal server error. The form displays fine and everything, its just when i press submit that it happens. the form is at This page

The code is as follows:

<?php 
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail('tburn76@gmail.com', $subject,
  $message, 'From:' . $email);
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mailform.php'>
  Email : <input name='email' type='text'><br>
  Subject: <input name='subject' type='text'><br>
  Message:<br>
  <textarea name='message' rows='15' cols='40'>
  </textarea><br>
  <input type='submit'  value='Send'>
  </form>";
  }
?>

Many thanks, Tommy

this is a problem in your hosting provider. 500 is a server error not a programming but you should do this before

change your seconde echo to this

  echo "<form method='post' action='".$_SERVER['PHP_SELF']."' name='email'>
  Email : <input name='email' type='text'><br>
  Subject: <input name='subject' type='text'><br>
  Message:<br>
  <textarea name='message' rows='15' cols='40'>
  </textarea><br>
  <input type='submit' name='email' value='Send'>
  </form>";

the code will be

<?php 
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail('tburn76@gmail.com', $subject,
  $message, 'From:' . $email);
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='".$_SERVER['PHP_SELF']."' name='email'>
  Email : <input name='email' type='text'><br>
  Subject: <input name='subject' type='text'><br>
  Message:<br>
  <textarea name='message' rows='15' cols='40'>
  </textarea><br>
  <input type='submit' name='email' value='Send'>
  </form>";
  }
?>

PS : i think that is not a code error but this will help you
good luck !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM