【问题标题】:How to output the checkbox value in the email template only if it is checked?仅在选中时如何在电子邮件模板中输出复选框值?
【发布时间】:2019-03-05 06:09:31
【问题描述】:

我正在开发一个项目,用户可以通过提供电子邮件地址将选中的复选框发送给客户。 html代码为:

<div class="row">
<div class="col-md-6 mx-auto">
    <form method="POST" action="/kidclinic/register">
        <div class="form-check">
            <input class="with-gap" value="http://test1.com" name="kidclinicchecbox1" type="checkbox" class="form-check-input" id="exampleCheck1">
            <label class="form-check-label">Text 1</label>
        </div> 
        <div class="form-check">
            <input class="with-gap" value="http://test2.com" name="kidclinicchecbox1" type="checkbox" class="form-check-input" id="exampleCheck1">
            <label class="form-check-label" >Text 2</label>
        </div> 
        <div class="form-check">
            <input class="with-gap" value="http://test3.com" name="kidclinicchecbox1" type="checkbox" class="form-check-input" id="exampleCheck1">
            <label class="form-check-label">Text 3</label>
        </div>        
        <div class="form-group">
            <label for="email">Send to</label>
            <input value="{{email}}" type="email" class="form-control" name="email" >
        </div>
        <p style="margin-top:16px"></p>
        <button type="submit" class="btn btn-primary">Send</button>
    </form>
</div>

我为每个输入复选框类型赋予了相同的名称,以便在检查值后获取该值。这个的输出是: html output

我正在使用 nodemailer 发送邮件。我的 nodemoailer 代码是。

const output = `
        <p>Fill up the forms</p>
        <h3>Please click the links</h3>
        <ul>
            <li>${req.body.kidclinicchecbox1}<br></li>
        </ul>                
    ` 

    async function main(){
        // create reusable transporter object using the default SMTP transport
       let transporter = nodemailer.createTransport({
         host: "hostname",
         port: 25,
         secure: false, // true for 465, false for other ports
         auth: {
           user: 'user.name', 
           pass: 'user.pass' // generated ethereal password
         },
         tls: {
           rejectUnauthorized: false
         }
       });
        // setup email data with unicode symbols
       let mailOptions = {
         from: '"Form App" ', // sender address
         to: req.body.email, // list of receivers
         subject: "Node contact Form app", // Subject line
         text: "Hello world?", // plain text body
         html: output // html body
       };
        // send mail with defined transport object
       let info = await transporter.sendMail(mailOptions)
        console.log("Message sent: %s", info.messageId);        
     }

一切正常,但我无法编辑电子邮件输出,这意味着我无法在输出中添加锚标记,也无法提供换行符。电子邮件输出如下所示email output。有没有办法在电子邮件的输出中添加锚标记?如果我遗漏了什么,请告诉我?

【问题讨论】:

    标签: node.js express nodemailer


    【解决方案1】:

    你没有在里面添加标签

  • 。检查此代码
    const output = `
            <p>Fill up the forms</p>
            <h3>Please click the links</h3>
            <ul>
                <li><a href="${req.body.kidclinicchecbox1}"> ${req.body.kidclinicchecbox1}</a><br></li>
            </ul>                
        `
    
  • 【讨论】:

    • 非常感谢它正在工作,但它显示在同一行。我可以问一下如何在它们出现在同一行时在链接之间换行吗?
    • 用逗号(,)分割,然后循环使用。
    猜你喜欢
    • 2022-10-26
    • 1970-01-01
    • 2013-12-09
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    • 2015-08-10
    相关资源
    最近更新 更多