Shivam
Shivam

Reputation: 103

How to remove special character from email using codeignitor

How to remove special character from email using codeignitor

Email is adding some special character don't know why and how this is going using codeignitor how to solve this this is my Email.php system file please guide

protected function _build_message()
    {
        if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
        {
            $this->_body = $this->word_wrap($this->_body);
        }

        $this->_set_boundaries();
        $this->_write_headers();

        $hdr = ($this->_get_protocol() === 'mail') ? $this->newline : '';
        $body = '';

        switch ($this->_get_content_type())
        {
            case 'plain' :

                $hdr .= 'Content-Type: text/plain; charset='.$this->charset.$this->newline
                    .'Content-Transfer-Encoding: '.$this->_get_encoding();

                if ($this->_get_protocol() === 'mail')
                {
                    $this->_header_str .= $hdr;
                    $this->_finalbody = $this->_body;
                }
                else
                {
                    $this->_finalbody = $hdr.$this->newline.$this->newline.$this->_body;
                }

                return;

            case 'html' :

                if ($this->send_multipart === FALSE)
                {
                    $hdr .= 'Content-Type: text/html; charset='.$this->charset.$this->newline
                        .'Content-Transfer-Encoding: quoted-printable';
                }
                else
                {
                    $hdr .= 'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"';

                    $body .= $this->_get_mime_message().$this->newline.$this->newline
                        .'--'.$this->_alt_boundary.$this->newline

                        .'Content-Type: text/plain; charset='.$this->charset.$this->newline
                        .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
                        .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline

                        .'Content-Type: text/html; charset='.$this->charset.$this->newline
                        .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline;
                }

                $this->_finalbody = $body.$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline;

                if ($this->_get_protocol() === 'mail')
                {
                    $this->_header_str .= $hdr;
                }
                else
                {
                    $this->_finalbody = $hdr.$this->newline.$this->newline.$this->_finalbody;
                }

                if ($this->send_multipart !== FALSE)
                {
                    $this->_finalbody .= '--'.$this->_alt_boundary.'--';
                }

                return;

            case 'plain-attach' :

                $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"';

                if ($this->_get_protocol() === 'mail')
                {
                    $this->_header_str .= $hdr;
                }

                $body .= $this->_get_mime_message().$this->newline
                    .$this->newline
                    .'--'.$this->_atc_boundary.$this->newline
                    .'Content-Type: text/plain; charset='.$this->charset.$this->newline
                    .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline
                    .$this->newline
                    .$this->_body.$this->newline.$this->newline;

            break;
            case 'html-attach' :

                $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"';

                if ($this->_get_protocol() === 'mail')
                {
                    $this->_header_str .= $hdr;
                }

                $body .= $this->_get_mime_message().$this->newline.$this->newline
                    .'--'.$this->_atc_boundary.$this->newline

                    .'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'.$this->newline.$this->newline
                    .'--'.$this->_alt_boundary.$this->newline

                    .'Content-Type: text/plain; charset='.$this->charset.$this->newline
                    .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
                    .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline

                    .'Content-Type: text/html; charset='.$this->charset.$this->newline
                    .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline

                    .$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline
                    .'--'.$this->_alt_boundary.'--'.$this->newline.$this->newline;

            break;
        }

        $attachment = array();
        for ($i = 0, $c = count($this->_attachments), $z = 0; $i < $c; $i++)
        {
            $filename = $this->_attachments[$i]['name'][0];
            $basename = ($this->_attachments[$i]['name'][1] === NULL)
                ? basename($filename) : $this->_attachments[$i]['name'][1];

            $attachment[$z++] = '--'.$this->_atc_boundary.$this->newline
                .'Content-type: '.$this->_attachments[$i]['type'].'; '
                .'name="'.$basename.'"'.$this->newline
                .'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline
                .'Content-Transfer-Encoding: base64'.$this->newline
                .(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline);

            $attachment[$z++] = $this->_attachments[$i]['content'];
        }

        $body .= implode($this->newline, $attachment).$this->newline.'--'.$this->_atc_boundary.'--';
        $this->_finalbody = ($this->_get_protocol() === 'mail')
            ? $body
            : $hdr.$this->newline.$this->newline.$body;

        return TRUE;
    }

What would be right approach to fix it please guide thanks in advance

one more thing i would like to tell i'm using smtp_crypto => tls that causing issue

Upvotes: 0

Views: 141

Answers (1)

G2 Jakhmola
G2 Jakhmola

Reputation: 811

You could fix this issue by replacing instances of _prep_quoted_printable in the Email class with the PHP native function quoted_printable_encode.

Just replace inside _build_message()

How this help you !

Upvotes: 4

Related Questions