0

I have been trying to do an email contact form with php i've read a couple books and done some online things but this php code isn't working:

test.php:

 <?php
if (isset ($_post['sendbutton'])) {
  $fname = $_post['fname'];
  $lname = $_post['lname'];
  $phone = $_post['phone'];
  $email = $_post['email'];
  $msg = $_post['msg'];
  if (empty($fname) || empty($lname) || empty($email) || empty($msg)) {
    $error = TRUE;
  } else {
    $recipient = 'jkminer1.jk@gmail.com';
    $subject = 'website contact';
    $body = "the following message was sent";
    $body .= "via your website contact form:\n\n";
    $body .= "name: $fname $lname\n";
    $body .= "email: $email\n";
    if (empty($phone) == FALSE) {
      $body .= "phone: $phone\n";
    }
    $body .= "\n$msg";
    $headers = "from: webform@domain\r\n";
    $headers .= "reply to: $email\r\n\r\n";
    $sent = (mail($recipient, $subject, $body, $headers));
    if ($sent) {
      $success = TRUE;
    }
  }
}
?>

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  <title>Contact form</title>
</head>
<body>
<?php if ($success); ?>
  <div style="margin: auto; text-align: center;">
    <h2>Thank you for contacting us.</h2>
    your email has been sent and we'll reply as sson as possable.
  </div>
<?php else; ?>
<?php if ($error); ?>
<div style="font-weight:bold; color:#ff0000;">
  please enter all the feilds that was printed in bold.
</div>
<?php endif; ?>
<p>if you have any questions please email about me.</p>
<form method="post" action="test.php">
  <strong>First name</strong>
  <input type="text" name="fanme" size="20" value="<?php $fname ?>"><br>
  <strong>last name</strong>
  <input type="text" name="lanme" size="20" value="<?php $lname ?>"><br>
  phone&nbsp;
  <input type="text" name="phone" size="20" value="<?php $phone ?>"><br>
  <strong>email</strong>&nbsp;
  <input type="text" name="email" size="<?php $email ?>"><br>
  <strong>type your question below</strong>
  <textarea name="msg" cols="50" rows="10"><?php $msg ?></textarea><br>
  <input type="submit" name="sendbutton" value="send">
<?php endif; ?>
</body>
</html>

I am open to other suggestions on doing a contact form.

Jake k
  • 1

0 Answers0