我正在编写一个 php 表单,并且想要一个非常轻便和简短的代码。验证码工作正常,验证也是如此。我有两个问题:测试时,我收到的电子邮件 1)显示人名作为电子邮件的主题 2)在消息字段中写的文本没有发送
请指教。
这是php:
<?php
session_start();
if(isset($_POST['submit'])) {
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$telephone = $_REQUEST['telephone'] ;
if(!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['telephone']) &&!empty($_POST['message']) && !empty($_POST['code'])) {
if($_POST['code'] == $_SESSION['rand_code']) {
if
(filter_var($email, FILTER_VALIDATE_EMAIL)) {
mail("youremail@something.something", $name, $telephone, "From:" . $email);
$accept = "Thank you for contacting me.";
}
else if (strpos($email, '@') !== false) {
$error = "Please verify your email";
}
else {
$error = "Please verify your email";
}
}
else {
$error = "Please verify that you typed in the correct code.";
}
}
else {
$error = "Fields with * are required";
}
}
?>
这里的HTML:
<body>
<?php if(!empty($error)) echo '<div class="error">'.$error.'</div>'; ?>
<?php if(!empty($accept)) echo '<div class="accept">'.$accept.'</div>'; ?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/form-data">
<p><input type="text" name="name" /> Name *</p>
<p><input type="text" name="email" /> Email *</p>
<p><input type="text" name="telephone" /> Contact Number *</p>
<p><textarea name="message"></textarea>Message</p>
<img src="captcha.php"/>
<p><input type="text" name="code" /> Are you human?</p>
<p><input type="submit" name="submit" value="Send" class="button" /></p>
</form>