2017-04-22 164 views
0

我正在构建一个基于Moodle的学习管理系统。我想为每封电子邮件添加一个电子邮件页眉和页脚。Moodle电子邮件模板

我在做一些Moodle的变化为如下的./lib/moodlelib.php添加图像:

function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '', $attachment = '', $attachname = '', 
         $usetrueaddress = true, $replyto = '', $replytoname = '', $wordwrapwidth = 79) { 

    global $CFG, $PAGE, $SITE; 
    // Append image at top 
    if($messagehtml){ 
     $tmp = $messagehtml; 

     // Added image here 
     $messagehtml = '<img src="'.$CFG->wwwroot.'/images/logo.png" alt="LMS" /><br/>'; 

     // $messagehtml = $image; 
     $messagehtml .= $tmp; 
    } 
    if($messagetext){ 
     $tmp = $messagetext; 
     // Added image here 
     $messagetext = '<img src="'.$CFG->wwwroot.'/images/logo.png" alt="LMS" /><br/>'; 
     // $messagehtml = $image; 
     $messagetext .= $tmp; 
    } 
    .................... 

,但我想要的页眉和页脚的固定模板。请帮帮我。

回答

3

你可以(或直属/lang/en或插件英文)创建一个language file消息标题,然后添加下面的字符串中的语言文件:

$string ['message_header'] = '<p> write here whatever your style and HTML structure you want in your header</p> 
adding your image as well <img src="'.$CFG->wwwroot.'/images/logo.png" alt="LMS" />'; 

然后,你可以写一个字符串您的页脚还有:

$string ['message_footer'] = 'Your HTML footer here'; 

最后,你可以在邮件中插入您的字符串:

$message = 'here your body'; 

// insert message header - if your language string is in /lang/moodle.php: 

$message = get_string ('message_header') . $message; 

// insert message footer - if your language string is in your /local/myplugin: 

$message .= get_string ('message_footer', 'local_my_plugin'); 

这样,如果您直接在语言文件中更改它们(或在数据库中),则可以随意自定义页眉和页脚。见here)。