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

我先检查了所有的问题。但他们都没有帮助解决我的问题。


我有连接到 HTML 联系表单的 PHP 电子邮件回复程序。我需要在发送给客户的电子邮件回复器中显示选定的复选框值。


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 表单中选定的复选框值 ŠKOLENIE:CHECKBOX HERE

有任何想法吗?谢谢


DIEA
浏览 35回答 2
2回答

皈依舞

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

MMTTMM

您没有这样的变量$post,但您尝试使用它两次。将其替换为$_POST,您的表单就可以工作了。这:$document&nbsp;=&nbsp;implode(",&nbsp;",$post['document']);替换为:$document&nbsp;=&nbsp;implode(",&nbsp;",$_POST['document']);它应该有效。一些提示:正确配置的 IDE 会让您了解诸如未声明变量之类的错误。使用 PHPStorm(商业)或 VSCode(免费)。不要在文件末尾关闭 php 标签 (?>) (PSR2):仅包含 PHP 的文件中必须省略结束 ?> 标记。不要多次使用相同的标识符 (id)。id 在整个 HTML 文档中应该是唯一的。编辑: // 正如有人在评论中提到的,你没有标签的结束标签<form>,但我假设你只粘贴了 HTML 文档的一部分。否则,您也应该纠正它。
打开App,查看更多内容
随时随地看视频慕课网APP