0

我正在编写一个 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>

4

1 回答 1

0

问题在于邮件功能。您传递的是姓名而不是主题和电话号码而不是消息。这是正确的格式。

邮件(字符串 $to ,字符串 $subject ,字符串 $message [,字符串 $additional_headers [,字符串 $additional_parameters ]])

于 2012-10-06T16:28:06.067 回答