我正在编写一个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>
答案 0 :(得分:0)
问题在于邮件功能。您传递的是姓名而不是主题和电话号码而不是邮件。这是正确的格式。
mail(string $ to,string $ subject,string $ message [,string $ additional_headers [,string $ additional_parameters]])