联系人/订阅表不将所有选定/输入的信息发送到电子邮件

时间:2015-03-08 16:28:28

标签: php html radio-button

搜索一下,无法找到/弄清楚如何解决我的问题。

创建一个表单,当输入电子邮件并选择单选按钮时,将向我发送一封包含该信息的电子邮件。但是,电子邮件地址即将结束,但单选按钮选择不是。我将不胜感激任何帮助!感谢。

HTML:

<div class="subscriber_info">
    <div class="subscriber_header">
        Subscribe to Scarlet & Maize
    </div>
    <div class="subscriber_image">
        <img src="NEW LOGO-150.png" />
    </div>
    <div class="subscriber_content">
        Receive fresh content for your favorite team straight to your inbox!<br /><br />

        Select your Team(s):<br />
        <div class="selection">
            <input type="radio" name="likeit" value="Michigan Wolverines" checked="checked" /> Michigan Wolverines<br />
            <input type="radio" name="likeit" value="Ohio State Buckeyes" /> Ohio State Buckeyes<br />
            <input type="radio" name="likeit" value="Both" /> Both
        </div>
    </div>
</div>
<div class="subscriber_contact">

    <form action="contact.php" method="post">
    <input type="text" name="email" placeholder="Enter Email Address" /> 
    <input type="submit" value="Subscribe">
    </form>  

</div>

PHP:

<?php
/* Set e-mail recipient */
$myemail  = "__________@gmail.com";

/* Check all form inputs using check_input function */


$email    = check_input($_POST['email']);
$likeit    = check_input($_POST['likeit']);


/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}

/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}

/* Let's prepare the message for the e-mail */
$message = "You have a new subscriber:

E-mail: $email
Favorite Team?: $likeit



End of message
";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: thanks.htm');
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>

<b>Please correct the following error:</b><br />
<?php echo $myError; ?>

</body>
</html>
<?php
exit();
}
?>

1 个答案:

答案 0 :(得分:0)

我认为你应该这样做$likeit = $_POST['likeit']

因为我找不到你在哪里定义$ likeit