2015-05-27 57 views
1

我试图设置一个表格,将通过电子邮件发送给我的人的回应。谷歌脚本援助

这是当前的脚本:

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 = '[email protected]'; 
    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); 
    } 
} 

这是它的外观时,我收到一封电子邮件: screenshot

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

我有类似的情况,这就是我如何解决它。 我创建了一个带有表格的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 

祝你好运!