Ticket #1462 (new enhancement)

Opened 6 years ago

Last modified 6 years ago

Send Plain Text emails

Reported by: ed209 Assigned to: somebody
Priority: normal Milestone:
Component: SGL - Emailer Severity: open
Keywords: Cc:

Description

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();

Change History

05/21/07 13:13:40 changed by 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.

05/22/07 03:17:47 changed by 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!