当在我的应用程序中添加新文章时,我在我的 cakephp 应用程序(2.2)中使用电子邮件组件向订阅的人发送电子邮件。
我使用 TinyMCE 允许管理员用户格式化文本,这会导致一些格式化的 HTML 保存在数据库中(这很好)但是我想通过电子邮件将整篇文章以电子邮件格式发送给选择的用户,包括 html 和纯文本。文章添加。这适用于 html 版本,但是如何从纯文本版本中剥离 html,同时将其保留在 html 版本中?到目前为止,这是我的代码:
public function admin_add() {
if ($this->request->is('post')) {
$this->NewsArticle->create();
if ($this->NewsArticle->save($this->request->data)) {
// If is a tech alart - send email
if ($this->request->data['NewsCategory']['NewsCategory']['0'] == '2') {
// Email users who have opted in to webform updates
$usersToEmail = $this->NewsArticle->query("SELECT username, tech_email FROM users WHERE tech_email = 1");
// Loop throughh all opt'ed in users
foreach ($usersToEmail as $user) {
$this->Email->template = 'newTechAlert';
$this->Email->from = 'Client Area <clientarea@someurl.co.uk>';
$this->Email->to = $user['users']['username'];
$this->Email->subject = 'New Technical Alert';
// Send as both HTML and Text
$this->Email->sendAs = 'both';
// Set vars for email
$this->set('techAlertTitle', $this->request->data['NewsArticle']['title']);
## NEED TO STRIP THE HTML OUT FOR NONE HTML EMAILS HERE - BUT HOW???
$this->set('techAlertBody', $this->request->data['NewsArticle']['body']);
$this->set('user', $user['users']['username']);
$this->Email->send();
}
}