Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
A form I have which sends submit data via

Code: Select all
cms:send_mail from='' to=frm_email cc='' subject='Your Form Submission' debug='1'>

Has stopped working after a recent Couch upgrade. It submits fine and the log.txt of debug info says it sent fine but in fact the emails are never received because the 'from' address is appended with extra text so the emails bounce.

SMTP error from remote mail server after end of data:
550-5.7.1 [ 13] Messages with multiple addresses in From:
550 5.7.1 are not accepted. d12si10208816wrb.469 - gsmtp
Additional. I tried sending the form without a BCC or CC and got a different error (bounce) because of malformed 'from' header...

From, charset=utf-8

I think this may be a PHP 8 mail issue? Mail headers should perhaps be sent to the mail command in an array as opposed to a string with carriage returns?
I think this may be a PHP 8 mail issue?

Yes, you are right.
PHP 8 seems to have an issue with the mail() function used by PHP -

The solution, for now, is not to use mail() function (the default with PHP) and use SMTP instead.
This is how we do it in Couch -

1. Enable phpMailer addon (viewtopic.php?f=5&t=10750).

2. By default, phpMailer itself uses the same mail() function so as the next step we need to make it use SMTP.
This can be done by renaming config.example.php found within couch/addons/phpmailer/ to config.php and making its contents as follows -
Code: Select all
   if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly
    // 1. Method used for sending emails.
    // Four valid options available:
    // 'smtp'       - Send messages using SMTP (e.g. GMail).
    // 'mail'       - Send messages using PHP's mail() function.
    // 'sendmail'   - Send messages using $Sendmail.
    // 'qmail'      - Send messages using qmail.
    $cfg['method'] = 'smtp';
    // 2. SMTP settings: required only if $cfg['method'] above is set to 'smtp'.
    $cfg['host']   = '';      // Address of the SMTP server. If left empty, defaults to 'localhost'.
    $cfg['port']   = '';                 // Port of the SMTP server. If left empty, defaults to '25'.   
    $cfg['secure'] = '';                 // encryption to use on the SMTP connection. Valid options are '', 'ssl' or 'tls'.
    $cfg['authentication_required'] = '0';  // set this to '0' if your SMTP server does not require authentication
        // If 'authentication_required' above is set to '1', the following credentials will be required
        //$cfg['username'] = '';
        //$cfg['password'] = 'your_password';

    // 3. Debug. If set to '1', will log all debug output in 'log.txt' at site's root.
    $cfg['debug'] = '0';   

Try setting debug above (temporarily) to '1'. Try sending a mail and the details of it should get logged in a file named log.txt in your site's root - more details of this debugging is in the same viewtopic.php?f=5&t=10750 post.

Hope this helps. Do let me know.
Thanks for your reply. Just saw it as I was about to post that I'd found my own solution to the problem by modifying the Couch send_mail function as follows (it's a bit of a 'hack'):

In file /couch/functions.php (Couch version 2.3) I changed the last lines of "function send_mail("


Code: Select all
           $arrayheaders = array(
                "From" => $from
            foreach(preg_split("/((\r?\n)|(\r\n?))/", $h) as $line)
                $tv = explode(":", $line);
                $t = trim($tv[0]);
                $v = trim($tv[1]);
                if (isset($t) and (strlen($t) > 0) and isset($v) and (strlen($v) > 0))
                    $arrayheaders[$t] = $v;

            return @mail( $to, $subject, $text, $arrayheaders );
        } # end of send_mail function

PS. The debug function in the email system was saying the emails had been sent fine. Because they were sent fine and processed correctly by PHP and the server, and delivered. But they were then bounced back. So as far as Couch was concerned the emails worked perfectly - no error reported.
Thanks for sharing the solution.
I'd appreciate if you could also try the one I suggested and let us know it if that works.
Will do so when I get 5. Thank you :)
6 posts Page 1 of 1