我先檢查了所有的問題。但他們都沒有幫助解決我的問題。我有連接到 HTML 聯系表單的 PHP 電子郵件回復程序。我需要在發送給客戶的電子郵件回復器中顯示選定的復選框值。PHP代碼<?phpif(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 = '[email protected]'; $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: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\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有任何想法嗎?謝謝
2 回答

皈依舞
TA貢獻1851條經驗 獲得超3個贊
應該
if(isset($_POST['document']) && count($_POST['document']) > 0) {
foreach($_POST['document'] as $doc){
if(isset($documents[$doc])){
$document = implode(", ",$_POST['document']);
$message = "
?KOLENIE: $document
";
}
}
}

MMTTMM
TA貢獻1869條經驗 獲得超4個贊
您沒有這樣的變量$post
,但您嘗試使用它兩次。將其替換為$_POST
,您的表單就可以工作了。
這:
$document = implode(", ",$post['document']);
替換為:
$document = implode(", ",$_POST['document']);
它應該有效。
一些提示:
正確配置的 IDE 會讓您了解諸如未聲明變量之類的錯誤。使用 PHPStorm(商業)或 VSCode(免費)。
不要在文件末尾關閉 php 標簽 (?>) (PSR2):
僅包含 PHP 的文件中必須省略結束 ?> 標記。
不要多次使用相同的標識符 (id)。id 在整個 HTML 文檔中應該是唯一的。
編輯: // 正如有人在評論中提到的,你沒有標簽的結束標簽<form>
,但我假設你只粘貼了 HTML 文檔的一部分。否則,您也應該糾正它。
- 2 回答
- 0 關注
- 150 瀏覽
添加回答
舉報
0/150
提交
取消