我正在尝试设置一个表单,通过电子邮件向我发送电子邮件回复。
这是当前的脚本:
function nl2br_(input_string){
return input_string.replace(/(\r\n|\r|\n)/g,'<br />');
}
function contactUsMailer(e) {
// This script e-mails the contents of a form to a given recipient
// The form must have three fields in the order of: name; e-mail address; and message
// You must change the recipient variable below to your e-mail address
try {
var recipient = 'myemail@hotmail.com';
var timestamp = e.values[0];
var username = e.values[1];
var option = e.values[2];
var details = e.values[3];
var body = username+' sent the following message: '+option ;
var bodyHTML = '\
<p>'+username+' <a href="mailto:'+username+'">'+option+'</a> below are the details </p>\
<blockquote>'+nl2br_(details)+'</blockquote>\
<p>Sent by the <a href="http://www.steegle.com/">Steegle.com</a> Contact Us Form Google Apps Script</p>';
var advancedArgs = {htmlBody:bodyHTML , replyTo:username};
MailApp.sendEmail(recipient, "Contact Us Form", body, advancedArgs);
} catch(e){
MailApp.sendEmail(recipient, "Error - Contact Us Form", e.message);
}
}
这是我收到电子邮件时的样子:
var timestamp - not important ignore it
var username - their username
var option - this is the "issue"
var details - detail of problem
我真的希望看起来像这样:
Username: "username here"
Issue: "issue here"
Details:
"wall of text for details here"
我已经在这一个半小时以上了,我不能让它看起来像上面显示的东西:/
答案 0 :(得分:0)
我有类似的情况,这就是我解决它的方式。 我创建了一个带有表格的HTML输出,然后将其作为我的电子邮件正文发送。
var log = HtmlService.createHtmlOutput()
log.append('<body><table border="1">');
log.append('<tr></td> Username: </td><td>' + usernameVAR +'</td></tr>');
log.append('<tr></td> ISSUE </td><td>' + issueVAR +'</td></tr>');
log.append('<tr></td> DETAILS </td><td>' + detailsVAR +'</td></tr>');
log.append('</table></body>');
var htmlContent = log.getContent();
MailApp.sendEmail(YOUR EMAIL GOES HERE ,"TITLE OF EMAIL", "SUBJECT LINE",{htmlBody:htmlContent} ) //Text as HTML
祝你好运!