2017-09-25 86 views
0

目前我使用下面的代码来发送在不含脂肪框架我的电子邮件:多发送文本和HTML电子邮件中不含脂肪框架

$smtp = new SMTP ($f3->get('MAILHOST'), $f3->get('MAILPORT'), $f3->get('MAILPROTOCOL'), $f3->get('MAILUSER'), $f3->get('MAILPW')); 
     $smtp->set('Content-type', 'text/html; charset=UTF-8'); 
     $smtp->set('Errors-to', '<$my_mail_address>'); 
     $smtp->set('To', "<$my_mail_address>"); 
     $smtp->set('From', '"$my_mailer_name" <$my_mail_address>'); 
     $smtp->set('Subject', "$subject"); 
     $smtp->set('Date', date("r")); 
     $smtp->set('Message-Id',generateMessageID()); 
$smtp->send(Template::instance()->render('emails/'.$mailTemplate.'.html')); 

它就像一个魅力。但是我想为这封电子邮件添加一个文本版本。

有没有办法在Fat Free Framework smtp插件中做到这一点? 如果是这样,我该怎么做? 如果不是,我该怎么做F3呢?

+0

综观[源代码](https://github.com/bcosca/fatfree-core/blob/master/smtp.php) ,似乎无法在一封电子邮件中发送同一邮件的两个版本(HTML +文本)。不过,您可以将文本版本作为单独的文件附加。 – xfra35

回答

0

其实它可以发送一个multiplart文本+ html邮件。 SMTP类仅仅是一个协议实现,所以在这一点上它可能会感觉有点缺乏。你基本上需要用多像这样准备邮件正文:

$text = 'Hello world.'; 
$html = 'Hello <b>world</b>'; 

$smtp = new \SMTP(); 
$hash=uniqid(NULL,TRUE); 
$smtp->set('From', '[email protected]'); 
$smtp->set('To', '[email protected]'); 
$smtp->set('Content-Type', 'multipart/alternative; boundary="'.$hash.'"'); 
$smtp->set('Subject', 'Multipart test'); 

$eol="\r\n"; 
$body = '--'.$hash.$eol; 
$body .= 'Content-Type: text/plain; charset=UTF-8'.$eol; 
$body .= $text.$eol.$eol; 
$body .= '--'.$hash.$eol; 
$body .= 'Content-Type: text/html; charset=UTF-8'.$eol.$eol; 
$body .= $html.$eol; 

$smtp->send($body,true);