简体   繁体   English

PHP - 电子邮件回复器中的复选框值显示

[英]PHP - checkbox value display in E-mail responder

I have checked all the questions first.我首先检查了所有问题。 But non of them helped to solve my problem.但他们都没有帮助解决我的问题。

I have PHP E-mail responder connected to HTML contact form.我将 PHP 电子邮件响应器连接到 HTML 联系表单。 I need to display selected checkbox value inside the email responder which is sent to customer.我需要在发送给客户的电子邮件响应器中显示选定的复选框值。

PHP code PHP代码

<?php

if(isset($_POST) && ($_POST['send'] == 1)){

    $documents = array(
                    'document1' => 'http://www.example.com/document1.doc',
                    'document2' => 'http://www.example.com/document2.doc',
                    'document3' => 'http://www.example.com/document3.doc'
                    'document4' => 'http://www.example.com/document4.doc'
                );

    $to      = 'lubosmasura@gmail.com';
    $subject = 'Prihláška na školenie';
    $name = $_POST['name'];
    $email = $_POST['email'];
    $document = implode(", ",$post['document']);
    
    

    if(isset($_POST['document']) && count($_POST['document']) > 0){
        foreach($_POST['document'] as $doc){
            if(isset($documents[$doc])){
             $document = implode(", ",$post['document']);
             $message = "
             ŠKOLENIE: $document
             ";
        }
        }
    }


    $headers = 'From: noreply@marcelaskolenia.sk' . "\r\n" .
        'Reply-To: noreply@marcelaskolenia.sk' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    mail($to, $subject, $message, $headers);
   }
   ?>

HTML code HTML代码

<form method="post" action="test.php">
    
                            <p class="center">Vyberte školenie</p>
                            <label class="container riadok"><p for="document" class="dolava">§20 Poučená osoba</p>
                            <input type="checkbox"  name="document[]" value="document1" id="document">
                            <span class="checkmark"></span>
                            </label>
                            <label class="container riadok"><p for="document" class="dolava">Aktualizácia: §21 AŽ §24</p>
                            <input type="checkbox"  name="document[]" value="document2" id="document">
                            <span class="checkmark"></span>
                            </label>
                            <label class="container riadok"><p for="document" class="dolava">§21 Elektrotechnik</p>
                            <input type="checkbox"  name="document[]" value="document3" id="document">
                            <span class="checkmark"></span>
                            </label>
                            <label class="container riadok"><p for="document" class="dolava">§24 Revízny technik</p>
                            <input type="checkbox"  name="document[]" value="document4" id="document">
                            <span class="checkmark"></span>
                            </label>
                            <p class="center">Vyplňte osobné údaje</p>
                            <input type="text" name="name" id="name" class="form-control" placeholder="Meno">
                            <input type="text" name="email" id="email" class="form-control" placeholder="Email">
                            <input type="tel" name="phone" id="phone" class="form-control" placeholder="Telefónne číslo" pattern="[0-9]+"  title="Zadajte iba čísla." required="required">
                            
<input type="hidden" name="send" value="1" />
 <button type="submit" value="SEND" id="submit" class="btn btn-primary"> ODOSLAŤ PRIHLÁŠKU</button>

Email responder works but it does not display selected checkbox value from HTML form behaind message ŠKOLENIE: CHECKBOX HERE电子邮件回复器工作,但它不显示从 HTML 表单隐藏消息 ŠKOLENIE 中选择的复选框值: CHECKBOX HERE

Any ideas?有任何想法吗? Thank you谢谢

You don't have such a variable as $post , but you try to use it twice.您没有$post这样的变量,但您尝试使用它两次。 Replace it with $_POST and your form will work.$_POST替换它,您的表单将起作用。

This:这个:

$document = implode(", ",$post['document']);

Replace with this:替换为:

$document = implode(", ",$_POST['document']);

And it should work.它应该工作。

Some hints:一些提示:

  1. Properly configured IDE will let you know about such errors as an undeclared variable.正确配置的 IDE 会让您知道诸如未声明变量之类的错误。 Use PHPStorm (commercial) or VSCode (free).使用 PHPStorm(商业)或 VSCode(免费)。
  2. Don't close php tag (?>) at the end of your file (PSR2):不要关闭文件末尾的 php 标签 (?>) (PSR2):

The closing ?> tag MUST be omitted from files containing only PHP.结束 ?> 标签必须从只包含 PHP 的文件中省略。

  1. Don't use the same identifier (id) multiple times.不要多次使用相同的标识符 (id)。 The id should be unique in the entire HTML document. id 在整个 HTML 文档中应该是唯一的。

Edit: // As someone has mentioned in the comments, you don't have a closing tag for <form> tag, but I assumed that you pasted only a part of your HTML document.编辑:// 正如有人在评论中提到的,您没有<form>标签的结束标签,但我假设您只粘贴了 HTML 文档的一部分。 Otherwise, you should correct that as well.否则,你也应该纠正它。

Should be应该

if(isset($_POST['document']) && count($_POST['document']) > 0) {
    foreach($_POST['document'] as $doc){
        if(isset($documents[$doc])){
            $document = implode(", ",$_POST['document']);
            $message = "
            ŠKOLENIE: $document
            ";
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM