我已经设置了 PHP 邮件程序来在我的网站上传递联系表单信息。我在整理多个复选框输入时遇到问题。它在电子邮件中显示为空。这里是表单 HTML 代码:<div class="form-group"> <label class="checkbox-inline"> <input name="time" type="checkbox" id="inlineCheckbox1" value="AM"> AM </label> <label class="checkbox-inline"> <input name="time" type="checkbox" id="inlineCheckbox2" value="PM"> PM </label> </div>在我的 PHP 代码中,我添加了以下内容来检查复选框是否有输入:if($_POST["time"]) { $time_array = $_POST['time']; $time_tostring = implode(", ", $time_array); }然后在邮件代码中,我添加了以下内容:$mail = new PHPMailer(true);try { //Server settings $mail->isSMTP(); $mail->Host = $config['host']; $mail->SMTPAuth = true; $mail->Username = $config['username']; $mail->Password = $config['password']; $mail->SMTPSecure = $config['secure']; $mail->Port = $config['port']; //Recipients $mail->setFrom($config['from'], $config['fromName']); $mail->addAddress($config['sendTo']); //$mail->addCC($config['sendToCC']); $mail->addBCC($config['sendToBCC']); //Content $mail->isHTML(true); $mail->Subject = 'Website Contact Form'; $mail->Body = '<p>Emptied on: ' . $_POST['day'] . "</p>" . "<p>Time: " . $time_tostring . "</p>" . "<p>Name: " . $_POST['name'] . "</p>" . "<p>Address: " . $_POST['address'] . "</p>" . "<p>Phone Number: " . $_POST['number'] . "</p>" . "<p>Email: " . $_POST['email'] . "</p>" . "<p>Where did you hear about us: " . $_POST['how'] . "</p>" . "<p>Service interested in: " . $_POST['comments'] . "</p>" ; $mail->send(); echo json_encode(['status' => true, "data" => 'Message has been sent']);} catch (Exception $e) { echo json_encode(['status' => false, "data" => "Message could not be sent\nMailer Error: " . $mail->ErrorInfo]);}发送的邮件中,时间为空,不显示任何值。我也直接尝试了下面的行,但它也不起作用。. "<p>Time: " . implode(', ', $_POST['time']) . "</p>" 我不知道为什么这不起作用。任何想法都是值得赞赏的。
- 1 回答
- 0 关注
- 101 浏览
添加回答
举报
0/150
提交
取消