Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
I have added a newsletter functionality to Couch CMS, based on a script I found on the web. The script is raw PHP, and I am running it between <cms:php> and </cms:php> tags, which works: except sending the mail itself. I have tried several methods of solving this problem, all to no avail. I am hoping to get some tips or leads from the community.

What did i try:

1/ Send using the script's build-in method, which is using on PHPMailer. It extends the PHPMailer class into its own MLMail class, causing my server to fill up memory. I end with a white screen and 'Backend Fatal: memory size exhausted' errors. It does not matter how big I set the PHP memory, it always ends with this error. (BTW I read on the internet that this was due to the extended class being in a different file than where the mail is sent from; when I fixed that, the memory exhaustion problem kept occurring).

2/ Send using Couch's send_mail tag. However, since I am using raw PHP, I cannot get my dynamically built up mail body to be sent. <cms:send_mail to=... from=... subject=...> echo $mailhtml; </cms:send_mail> will literally send "echo $mailhtml;" as email content !

3/ Using PHPMailer class directly, so without extending it into a MLMail class as the script is doing by default. When I do this, I end up with errors like "Backend fatal error: PHP Fatal error: Uncaught Error: Class 'PHPMailer' not found in /home/xxx/xxx/xxx/public_html/couch/tags.php(3190)" because Couch will try to handle everything in its own way (which I can understand, of course).

For now, the best direction seems to be using the cms:send_mail function, because it is standard Couch, but how can I get the bodytext to appear between the <cms:send_mail> tags in raw PHP code?
All help and hints appreciated !
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
Code: Select all
<cms:send_mail to=... from=... subject=...><cms:php>global $mailhtml; echo $mailhtml;</cms:php></cms:send_mail>
Yes! That works. Many thanks !

One question left though... Now I have to place my recipients list $recipients into the <cms:send_mail> tag. I have tried various things, but again to no avail. How would I do that?

Code: Select all
<cms:send_mail to='<cms:php>global $recipients; echo $recipients;</cms:php>' from=...

does not work.
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
Please use double-quotes to set the parameter -
Code: Select all
<cms:send_mail to="<cms:php>global $recipients; echo $recipients;</cms:php>" from=...

More info on quotes - https://docs.couchcms.com/concepts/sett ... eters.html
Thanks. I am trying this from raw php code, and no matter what I try I do not succeed in sending the email.
Here's part of my code:

Code: Select all
$messagehtml = build_content($body,$maillist);                         
// send mail
if ($bEmailSend == TRUE) {   
   echo "bcc: " . $bcc_list;
   echo "<br>msg: " . $messagehtml;
   <cms:send_mail to="newsletter@mydomain.nl" bcc="<cms:php>global $bcc_list; echo $bcc_list;</cms:php>" from="fromaddress@mydomain.nl" subject="test" html="1" >
      <cms:php>global $messagehtml; echo $messagehtml;</cms:php>
   </cms:send_mail>


The mail is not delivered, this is what I see in my inbox:
A message that you sent contained no recipient addresses, and therefore no
delivery could be attempted.


Also, despite the fact that I thought that trendomen's advice worked, it does not: the text is not placed in the mail. I tested this by hardcoding my mail address and observing the mail: it is empty.

The headers do not show the 'to' nor the 'bcc' addresses, but show the 'from' address. The difference between the various addresses is that the from address is hard-coded, as you can see in the code snippet. The echo results in the correct mail address being echoed, so the variable is correct. My conclusion is that the variables are not resolved and used.

The web log contains this:
Backend fatal error: PHP Fatal error: Uncaught Error: Call to a member function Send() on null

What can I do about this? How to include php values in cos tags in raw php code?
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
There are various threads on raw php with Couch.. The main idea is that within cms:php block, couch tags have a priority over php code and outside cms:php core php has the priority.
Having priority, cms:send_mail goes first and php variables are not yet ready for it.
More here - viewtopic.php?f=2&t=10763#p27327 and viewtopic.php?f=2&t=10763#p27318
Thanks, that explains a lot !
I am going to refactor the raw PHP code that I took from the open source simple mail list script, into Couch code. I will then use raw PHP between <cms:php> tags only here and there, for some specific functions like reading the recipients from the database and building the content html.
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
You can also read any non-couch database with couchcms - cms:query.
8 posts Page 1 of 1
cron