【问题标题】:Display checkbox input in mail body PHPmailer在邮件正文 PHPmailer 中显示复选框输入
【发布时间】:2018-10-01 23:11:39
【问题描述】:

首先,我尝试回显我的复选框字段的结果,它显示正常。但是,当我将复选框名称放在 PHPmailer 设置中时,我的邮件只显示单词数组。

我知道这与复选框中的数组结果有关,但我不知道如何将结果放入邮件正文中。请给我一些建议和解释。

这是我的 HTML 复选框代码

<form method="post">
<div class="form-group">
    <p>If yes, which type of disposable contact lens have you worn before?</p>
    <input type="checkbox" name="disposable_lens[]"  value="Monthly"/> Monthly<br>
    <input type="checkbox" name="disposable_lens[]"  value="Daily Disposables"/> Daily Disposables<br>
</div>
</form>

这是我的 PHP 代码来回显结果,并在检查时显示两个值

if(empty($_POST["disposable_lens"]))
{
    $error .= '<p><label class="text-danger">Disposable_lens is required</label></p>';
}
else
{
    $disposable_lens = clean_text($_POST["disposable_lens"]);
    echo $disposable_lens."</br>";
}

这里我的 PHPmailer 正文代码仅在我的邮件中显示单词“array”,并且在我单击提交按钮时也显示错误

$mail->Body = join('', array(
        "Outlet: ",
        $_POST['outlet'],
        "<br/>",
        "Full Name: ",
        $_POST['fullname'],
        "<br/>",
        "Email Address: ",
        $_POST['email'],
        "<br/>",
        "Phone Number:",
        $_POST['contact_no'],
        "<br/>",
        "Have you worn contact lens before?: ",
        $_POST['lenses'],
        "<br/>",
        "If yes, which type of disposable contact lens have you worn before?: ",
        ($_POST['disposable_lens']),
        "<br/>",
        "Appointment Date ",
        $_POST['date'],
        "<br/>",
        "Appointment Time ",
        $_POST['time']
        )); 

这里的回显结果显示了我的复选框值,但在邮件中,只显示单词“array”。

【问题讨论】:

  • 我不建议将表单元素放在电子邮件中。这是非常不可靠的。最好发送一个指向网络表单的链接。

标签: php html arrays string phpmailer


【解决方案1】:

$_POST['disposable_lens'] 是所有复选框值的数组。当您将数组转换为字符串时,您只会得到Array。如果您想要一个逗号分隔的列表,请使用implode()

   "If yes, which type of disposable contact lens have you worn before?: ",
    implode(', ', $_POST['disposable_lens']),

【讨论】:

  • 仅供参考,implode() 与您之前在代码中使用的 join() 相同。所以看起来你已经知道了。
猜你喜欢
  • 1970-01-01
  • 2020-10-15
  • 1970-01-01
  • 1970-01-01
  • 2013-09-08
  • 2016-11-04
  • 2013-06-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多