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

When sending html mails, some customers did not receive the mails, or the spam filter of their mail provider found that our mails might be spam. In several internet forums I read that html mails schould always include an additional text only message.

How could I achieve this with the send_mail tag in couchcms?

Kind regards,
Olliwalli
Any email should include Content-Type. It is either text/html or text/plain. It means mail can't be sent as both html and plain at the same time. The advice on forums probably is not about it.

So, I guess, you just need to send it as html='1', but compose message with a plain text after the tags. Couch will pass all content of your message without changes, so it's you who decides what to place after or before the <html></html> tags in your message.

Couch's send_mail is used for with occasional mailing, as far as I can see. For mass mailing it's probably better have an account with some whitelisted service. Delivering your messages to multiple clients is not a scope of CMS only. It's a very broad question. Technically, Couch can pump lots of mails in a second :)
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
@Trendoman
It means mail can't be sent as both html and plain at the same time.

While you are right that a mail can only have one content-type, your observation quoted above is not quite right. HTML mails can contain an alternate plain text version of the message embedded within them (this is primarily for email clients that do not support HTML mails).

@olliwalli, I suggest you please try the phpMAiler addon (viewtopic.php?p=22911#p22911). I think it automatically embeds the plain text version of the richtext. Please let me know if it helps.
Thanks.

In this link it is described, how to generate a multipart mail with a html and a plain text version: http://kevinjmcmahon.net/articles/22/ht ... rt-email-/

Actually the message part of the my mails consist of only html content. To add an extra plain text part in the message I might include a multipart message body, but I'm not sure how to implement this, since it needs a boundary.

As I suppose, send_mail generates its own boundary. So if I create a message body with an different boundary, will the mail format be correct?

Any idea?
Thank you guys, my flop :)

As to the link, they say Headers must include 'Content-Type: multipart/alternative;boundary' and this thing is not present with plain and simple send_mail tag. But phpmailer addon, which extends send_mail should include such things.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
@olliwalli, IMHO, using phpMailer addon would be the easiest method (and also the most likely to escape the spam tag). I'd suggest again that, instead of trying hand-code every nuance, you give the addon a try.
Hi KK

I installed PHPMailer. For simultaneously sending plain text and html I had to modify the file phpmailer.php in /couch/addons/phpmailer and add a AltBody variable:

Code: Select all
            // subject and body
            $mail->Subject  = $subject;
            $mail->Body     = $text;
         
         // Added for plain text part
            $mail->AltBody  = preg_replace( "/\n\s+/", "\n", rtrim(html_entity_decode(strip_tags($text))) );

            // debug?
            if( $this->config['debug'] ){



With this modification, PHPMailer generates a multipart message. So this worked fine for me when sending a single mail.

Then I uploaded it to my site that can send multiple mails using pages tag. After trying to send 2 or 3 mails in one step, the page could not be loded anymore. There was an error in the browser stating that the page could not be loaded (I run the mailer in a backend admin page).

So as it seems PHPMailer using SMTP is not fast enough to send multiple mails in a loop.

Anyone an idea how to solve this?

Please try something like:

Code: Select all
<cms:set mail_list='mail1@domain.com|mail2@domain.com|mail3@domain.com|...' />
<cms:each mail_list>
  <cms:send_mail from='myaddres@domain.com' to=item subject='testmail' html='1'>
     <html>
     ....
     </html>
  </cms:send_mail>
</cms:each>


Wonder if it works for sombody out there with the phpmailer addon.
PhpMailer has a lot of settings. Maybe something makes it behave so. I'd try some like SMTPKeepAlive, Timeout etc. in class.phpmailer.php
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
@olliwalli, please try editing the 'couch\addons\phpmailer\phpmailer.php' file -
Find the following line of code (line 28)
require K_COUCH_DIR . 'addons/phpmailer/PHPMailer/PHPMailerAutoload.php';

- and change it to the following
require_once K_COUCH_DIR . 'addons/phpmailer/PHPMailer/PHPMailerAutoload.php';

Please let me know if this helps.
I tried it, but it did not help.

My first tests showed that after 7 mails the page breaks, the browser sais "The page does not work". For sending 7 mails, phpmailer (sending mails via smpt) needs about 3.5 seconds for one mail to send.

If changing the option to sending mails via 'mail', it needs only about 1 second for all mails.

See attached screenshots.

I created a test-script that sends a definable number of mails for checking performance and options. Please see the script in the attached zip file.

At the moment I think my solution is to use PHPMailer addon and set the option to send mails via mail. This ist fast and the requirement for multipart mail with an additional plain text part ist met.

Attachments

10 posts Page 1 of 1