我是开发新手,并且一直在努力工作,试图找出如何将复选框结果发送到我的电子邮件中。我已阅读并尝试了多个选项,但我找不到但没有一个可行。请让我知道我做错了什么!
HTML
<form id="contactForm" action="form_to_email.php" method="post" >
<fieldset class="contact">
<label class="labelOne" for="name">Name <span>*</span></label>
<input type="text" name="name"size="30" required />
<label for="email">Email <span>*</span></label>
<input type="text" name="email" size="30" required/>
<label for="message">Message</label>
<textarea id="message" name="message"
type= "text"minlength="2"></textarea>
<label for="phone">Cell Phone</label>
<input type="text" name="phone" size="15" />
</fieldset>
<fieldset class="checkboxes">
<p>I am interested in ...</p>
<label for="runstrong"><input class="checkbox" type="checkbox"
name="interest[]" value="runstrong">runstrong</label>
<label for="bestrong"><input class="checkbox" type="checkbox"
name="interest[]" value="bestrong">be strong</label>
<label for="runstrong"><input class="checkbox" type="checkbox"
name="interest[]" value="subscribe">receiving your newsletter</label>
<label for="personal training"><input class="checkbox"
type="checkbox" name="interest[]" value="personal training">
personal training</label>
</fieldset>
<fieldset>
<input class="btn" type="submit" value="Send" name="submit" />
<input class="btn" type="reset" value="Clear Form" name="reset" />
</fieldset>
</form>
PHP
<?php
/* Set e-mail recipient */
$myemail = "myemail@verizon.net";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "First and Last Name");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");
$phone = check_input($_POST['phone']);
$interest = isset($_POST['interest'])
? implode(',',$_POST['interest'])
:'intersted in';
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Cell phone :$phone
Message:$message
Interest:$interest
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location:thank_you.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Please hit the back button and try again</p>
</body>
</html>
<?php
exit();
}