PHP电子邮件表单不起作用,无法理解为什么?

时间:2015-07-27 13:52:52

标签: php html email contact-form

我一直在尝试用php做一个电子邮件联系表格,我已经阅读了几本书并做了一些在线的事情,但是这个PHP代码并没有工作:

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>

我愿意接受有关联系表格的其他建议。

0 个答案:

没有答案