【发布时间】: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