我一直在尝试用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
<input type="text" name="phone" size="20" value="<?php $phone ?>"><br>
<strong>email</strong>
<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>
我愿意接受有关联系表格的其他建议。