使用答案中的值标签使用PHP发送邮件

使用答案中的值标签使用PHP发送邮件,php,html,email,label,Php,Html,Email,Label,我想让我的访客勾选一些复选框。 当他们提交表单时,我想检查选中了哪些复选框,然后向访问者发送电子邮件。 我的问题是,我不想显示值,而是显示标签 因此,如果有人选中了bike复选框,我想发送一封包含$bike文本的电子邮件,但我想显示标签而不是值 <input type="checkbox" name="vehicle" value="bike"> <label for="bike">This is my bike</label> <input type=

我想让我的访客勾选一些复选框。 当他们提交表单时,我想检查选中了哪些复选框,然后向访问者发送电子邮件。 我的问题是,我不想显示值,而是显示标签

因此,如果有人选中了bike复选框,我想发送一封包含$bike文本的电子邮件,但我想显示标签而不是值

<input type="checkbox" name="vehicle" value="bike">
<label for="bike">This is my bike</label>
<input type="checkbox" name="vehicle" value="car">
<label for="car">This is my car</label>
<input type="checkbox" name="vehicle" value="bus">
<label for="bus">This is my bus</label>
<input type="checkbox" name="vehicle" value="plane">
<label for="plane">This is my plane</label>
<input type="checkbox" name="vehicle" value="train">
<label for="train">This is my train</label>
<input type="submit" value="Submit">

标签不会传递给PHP。您需要在后端使用逻辑将train转换为This is my train。

我只需要构建一个单页执行/表单类。__构造只是采用硬编码的值,但是您可以为数据库连接提供数据,并在那里返回一个数组。
        class   Vehicles
            {
                protected $array;

                public  function __construct()
                    {
                        $this->array['vehicle']['bike']     =   'This is my bike';
                        $this->array['vehicle']['car']      =   'This is my car';
                        $this->array['vehicle']['bus']      =   'This is my bus';
                        $this->array['vehicle']['plane']    =   'This is my plane';
                        $this->array['vehicle']['train']    =   'This is my train';
                    }

                public  function Form()
                    { ?>
        <form method="post" action="">
            <input type="hidden" name="command" value="true" /><?php
        foreach($this->array as $type => $kind) {
                foreach($kind as $key => $value) {?>
            <input type="checkbox" name="<?php echo $type; ?>[]" value="<?php echo $key; ?>">
            <label for="<?php echo $key; ?>"><?php echo $value; ?></label>
                <?php }
            } ?>
            <input type="submit" value="Submit">
        </form>
        <?php       }

                public  function SendMail($email)
                    {
                        if(isset($_POST['command']) && $_POST['command'] == 'true') {

                                foreach($_POST['vehicle'] as $value) {
                                        if(isset($this->array['vehicle'][$value]))
                                            $selection[]    =   $this->array['vehicle'][$value];
                                    }

                                $subject    =   "Subject: Vehicle Selected";
                                $message    =   implode("\r\n",$selection);
                                $header     =   "From: Automator Send<email@from.addr>";
                                if(mail($email,$subject,$message,$header))
                                    echo 'Sent';
                            }
                        else
                            $this->Form();
                    }
            }
            // Initiate Class
            $Automaker  =   new Vehicles();
            // Run main function 
            $Automaker->SendMail('email@address.com'); ?>
标签不是输入字段,因此不会发送到服务器。为什么会这样?它们不会改变,服务器知道它们是什么

在所有情况下,您可能首先使用translate数组生成字段:

foreach ($translate as $value=>$label)
{
    echo "<input type='checkbox' name='vehicle[]' value='$value'>\n"
    echo "<label for='$value'>$label</label>\n"
}

到目前为止你试过什么?我只看到HTML表单的一部分,没有打算发送电子邮件的代码。
foreach ($translate as $value=>$label)
{
    echo "<input type='checkbox' name='vehicle[]' value='$value'>\n"
    echo "<label for='$value'>$label</label>\n"
}