Problems, need help? Have a tip or advice? Post it here.
16 posts Page 1 of 2

For those, who are having problems with utf-8, something to this: viewtopic.php?f=4&t=3764, here is the solution.

Well, the original fix didn't work for me - so here are the key things for those, who need the contact form to be able to hand latin extended (for my case: ā, č, ģ, ī, ķ, ļ, ņ, š, ū, ž;)



@ /couch/includes/email.php

Code: Select all
 // Set HTML
    function setHTML($charSet = 'iso-8859-1') {
        if($charSet) {
           $tmp1 = $this->addHeader('MIME-Version', '1.0');
           $tmp2 = $this->addHeader('Content-type', 'text/html; charset=' . $charSet);
       } else {
           $tmp1 = $this->addHeader('MIME-Version');
           $tmp2 = $this->addHeader('Content-type');

change "iso-8859-1" -> "utf-8", this will make message work, if end-user chooses to "View All The Headers And Message

@ /couch/functions.php

Code: Select all
        function send_mail( $from, $to, $subject, $text, $headers="" ){
            // Source:
            if( strtolower(substr(PHP_OS, 0, 3)) === 'win' ){
                $mail_sep = "\r\n";
                $mail_sep = "\n";
            $h = '';
            if( is_array($headers) ){
                foreach( $headers as $k=>$v ){
                    $h .= $this->_rsc($k).': '.$this->_rsc($v).$mail_sep;
                if( $h != '' ) {
                    $h = substr($h, 0, strlen($h) - strlen($mail_sep));
                    $h = $mail_sep.$h;
            $from = $this->_rsc( $from );
            $to = $this->_rsc( $to );
            $subject = $this->_rsc( $subject );
            if ( defined('K_USE_ALTERNATIVE_MTA') && K_USE_ALTERNATIVE_MTA ){
                return @email( $to, $subject, $text, 'From: '.$from.$h );
                return @mail( $to, $subject, $text, 'From: '.$from.$h );

define headers array - it must be clearly defined array, otherwise it won't work - this actually adds real headers to the message
Code: Select all
            $headers    = array
                "MIME-Version" => "1.0",
                "Content-Type" => "text/html; charset=UTF-8",

add the new code just before

Code: Select all
            $h = '';

Long story short - you can add more headers using this method - original mail headers are:

Code: Select all
Return-path: <>
Envelope-to: rxxx@mxxx.lx
Delivery-date: Wed, xx Aug 2013 21:24:16 -0500
Received: from xxxxx by with local (Exim 4.80)
(envelope-from <>) id xxxxxx-xxxxxx-xx for
rxxxx@mxxxx.lx; Wed, xx Aug 2013 21:24:16 -0500
To: rxxxx@mxxxx.lx;
Subject: test message
X-PHP-Script: for xx.xx.148.117
Message-ID: <>
Date: Thu, 15 Aug 2013 05:24:16 +0300

Compare this to any e-mail message header you usually receive, and you may see some points as to why this feature could be useful to some sites, other than fixing utf-8 bugs.

Hope this helps someone.
This is obviously a newbie fix, as I am sure Kamran could figure on how to pass headers directly from email.php, never touching functions.php - I didn't but I used the mentioned sources (thanks for referring just near function :) )

Any Example - PHP Send

And it worked out for me;
Hi @lolsteamroller,

Thank you for digging deeper into the problem :)
I can now see that explicitly setting the charset in email header should rectify the problem in email clients that do not automatically work it out.

Making changes to either email.php or functions.php won't be required. The best place would be the 'tags.php' ('send_mail' tag specifically) which is the one that invokes those two scripts.

I've modified the existing 'send_mail' tag. Please copy/paste the following code to replace the 'send_mail' function completely in your tags.php file (please also revert back to the original
/couch/includes/email.php and /couch/functions.php).

The new code automatically uses the charset value specified in config.php ('utf-8' by default) though you can override that using the new 'charset' parameter the 'send_mail' tag now supports.
Code: Select all
function send_mail( $params, $node ){
    global $FUNCS;
    extract( $FUNCS->get_named_vars(
    $from = trim( $from );
    $to = trim( $to );
    $cc = trim( $cc );
    $bcc = trim( $bcc );
    $reply_to = trim( $reply_to );
    $return_path = trim( $return_path );
    $charset = trim( $charset );
    if( $charset=='' ) $charset=K_CHARSET;
    $debug = ( $debug==1 ) ? 1 : 0;
    $logfile = trim( $logfile );
    foreach( $node->children as $child ){
        $html .= $child->get_HTML();
    $headers = array();
    if( $cc ) $headers['Cc']=$cc;
    if( $bcc ) $headers['Bcc']=$bcc;
    if( $reply_to ) $headers['Reply-To']=$reply_to;
    if( $return_path ) $headers['Return-Path']=$return_path;
    $headers['Content-Type']='text/plain; charset='.$charset;
    $msg = $FUNCS->unhtmlentities( $html, K_CHARSET ); // resurrecting (decoding) the entities. Shouldn't be required in HTML mails.
    $msg = strip_tags($msg);
    $rs = $FUNCS->send_mail( $from, $to, $subject, $msg, $headers );
    if( $debug ){
        $log = "From: $from\r\nTo: $to\r\n";
        foreach( $headers as $k=>$v ){
            $log .= $k .': '.$v."\r\n";
        $log .= "Subject: $subject\r\nMessage: $msg\r\n\r\n";
        ( $rs ) ? $log .= "Delivery Success" : $log .= "Delivery Failed";
        $FUNCS->log( $log, $logfile );

Please try it out and let me know if this solves your problem.
I'll include the amendments to the core if it does.

Hey, Kamran!

I've reverted two of those files and included your code! Everything works as intended.

Thank you for taking the time to test out the fix.
I'll add it to the code-base.
ask for a little help :)
I followed all the advice in this post and the situation is as follows:
Body text of the email is ok, but text in subject it is unreadable (see att picture)

Can we solve this?


The fix was not needed for the current version (1.4.7) of Couch so if you happened to modify anything please revert back to the current code.

Assuming you see the problem with the current version, could you please sending an email to GMail and see if the problem appears there too?

Please let me know. Thanks.
thanks for the reply КК :)
Yes - in Gmail everything is fine, also in Yahoo, but - not ... unfortunately
As we can guess my client have email is right there :D :D :D :D :D

My question is - can send_mail tag to send simultaneously in more headers, for example:

Code: Select all
                  $headers = "MIME-Version: 1.0\r\n";
                  $headers .= "Content-type: text/html; charset=windows-1251\r\n";
                  $headers .= "From: ".$yourname." <".$email.">\r\n";
                  $headers .= "Reply-To: ".$email."\r\n";
                  $headers .= "X-MSMail-Priority: High\r\n";
                  $headers .= "X-Mailer: iCEx Networks HTML-Mailer v1.0\r\n";

I admit I have no idea
The 'from', 'reply_to' etc. parameters of cms:send_mail get automatically converted internally to the headers you mentioned. To add more custom headers, you'll need to tweak the PHP code directly.
The problem exists only with subject text, KK please give advice on what to add to try to fix the problem
16 posts Page 1 of 2

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 4 guests