2012-05-23 151 views

回答

2

我通常使用表中我的郵箱,但我認爲應該<br />工作

+0



取決於預期的行爲。 – Alexis

+0

_line break_是** BR ** http://www.w3.org/TR/html401/struct/text.html#h-9.3.2.1 – Edo

6

如果你不發送HTML格式的郵件,使用「\ n」。我個人鄙視HTML格式的電子郵件。

+0

同樣重要的是要注意許多垃圾郵件過濾器不會像html – Sherlock

4

發送電子郵件的HTML部分時,您應該使用<br>標記。

下面是關於如何撰寫相同電子郵件正文的示例,但格式不同的HTML &純文本。 (不是最好的代碼,但希望它說明了這一點)

function onFormSubmit(e) { 
    var subject = "Subject"; 

    // Collect user data 
    var name = e.values[0]; 
    var email = e.values[1]; // Where user enters his/her email address 

    // Generate content - Replace this with what you're composing 
    var content = []; 
    content.push("Hi " + name); 
    content.push("Thanks for submitting the survey!___LINE_BREAK___"); 
    content.push("Survey Team"); 

    // Combine content into a single string 
    var preFormatContent = content.join('___LINE_BREAK___'); 

    // Replace text with \n for plain text 
    var plainTextContent = preFormatContent.replace('___LINE_BREAK___', '\n'); 
    // Replace text with <br /> for HTML 
    var htmlContent = preFormatContent.replace('___LINE_BREAK___', '<br />'); 

    MailApp.sendEmail(email , 
        subject, 
        plainTextContent ,      
        { 
         name: "Survey Team", 
         html: htmlContent 
        }); 
} 
+0

替換隻搜索第一個實例,雖然有點麻煩,但我的解決方案是preFormatContent.split('___ LINE_BREAK ___')。join('\ n'); – Hovo

2

換行中msgBox

Browser.msgBox('line 1 \\\n line 2'); 

請注意,你需要逃跑「\ n」額外的反斜線。

相關問題