demianturner / sgl-docs-tickets-migration-test

0 stars 0 forks source link

Send Plain Text emails #1462

Open demianturner opened 11 years ago

demianturner commented 11 years ago

Be able to send plain text emails with SGL_Emailer().

This requires an update to latest version of http://pear.php.net/manual/en/package.mail.mail-mime.php or just edit lib/pear/Mail/mime.php line 312 (replace complete function)

{{{

function &_addTextPart(&$obj, $text) { $params['content_type'] = 'text/plain'; $params['encoding'] = $this->_build_params['text_encoding']; $params['charset'] = $this->_build_params['text_charset']; if (is_object($obj)) { return $obj->addSubpart($text, $params); } else { $obj = new Mail_mimePart($text, $params); return $obj; } }

}}}

Then in lib/SGL/Emailer.php add a class variable:

{{{ var $plainText = false; }}}

and replace line 116:

{{{ $this->html = $this->headerTemplate . $body . $this->footerTemplate; }}}

with

{{{ if ( $this->plainText ) { $this->html = $body; }else { $this->html = $this->headerTemplate . $body . $this->footerTemplate; } }}}

and line 134:

{{{ $mime->setHTMLBody($this->html); }}}

with this:

{{{ if ( $this->plainText ) { $mime->setTXTBody($this->html); } else { $mime->setHTMLBody($this->html); } }}}

then when sending a new plain text email:

{{{ $message = & new SGL_Emailer(array(of options)); $message->plainText = true; $message->prepare(); $message->send(); }}}

demianturner commented 11 years ago

[mickey] cool, nice idea but better not this line:

$message->plainText = true;

to enable plain text emails. a new preference would be better. so every registered users can set the desired delivery method.

and maybye html tags should be stripped out before the setTXTBody method?

cheers

m.

demianturner commented 11 years ago

[ed209] I was thinking of this totally from a site admin point of view - basically emails generated by actions on the site (registrations, comments etc) rather than the user choosing at the point of sending an email.

The above is only really a quick fix as I don't think Emailer.php really takes full advantage of the Pear mail package - in theory Emailer.php should be able to set Plain Text and HTML parts of the email, but that requires more work (I'm not sure I'm good enough to do it).

Also, the way that I use it on my site is that I don't pass HTML to setTXTBody method, only plain text. I have to admit that my alterations are not very flexible!