Newsletter plugin (sort of)

Hi all,

I started sort of a plugin a while ago which is intended to add a newsletter function to kirby.

I am by no means a developer in PHP or web stuff. I posted the code and files to github since I have no idea on how to move on with this.

Perhaps you can grab the code and develop it to a decent newsletter addon for kirby :wink:

“Features”

Whats missing:

  • make a better monitoring of sending emails
  • add some kind of ‘abort’ funcitonality to the system process (shell_exec)
  • make a better kirby app and use kirbys full potential with plugin/controllers, etc.

/edit:
It’s been done: Newsletter plugin v2

3 Likes

What I would love to see as a newsletter kinda thing is it to be working like the following:

Registering using kirby account system as user-group “newsletter”.

A script to compose a newsletter which is being send to users via the built in send email function. But easier said than done right ? :smile:

1 Like

not necessarily :smile:

I did not want to use the mail() function, since emails sent this way get marked as spam more often.
At least that’s what I experienced.


anyway. :wink:
What came up my mind regarding your suggestion is:

you can trigger the script by adding a checkbox to your post blueprint:

 newsletter:
   label: Newsletter
   type: checkbox
   width: 1/2
   text: check if it should be marked as newsletter (for sending via email).

Not sure how to start the “send process” properly
 I created a send.php which gets called by clicking on a link/button.
There might a better way to do this. :wink:

Basically “send.php” does this:

  • grab the latest post marked as “newsletter”
  • grab all users in the users file/“post”
  • trigger the php-mailer for each user in a loop.

I weren’t asking for suggestions how to do it. I was just sharing my own idea how I would have loved seeing it working this way.

1 Like

I was over-motivated, I guess. :wink:

I think with the new panel widgets this might become awesome!
You could have a panel much like the one for pages, but solely for newsletters:

You can add/edit/delete with normal panel functionality because they’re basically just pages but also manage them a bit more easily with their own widget?

I personally like the idea with a special user role. Nevertheless there should be an option to specify more recipients by uploading a file (e.g. CSV) with addresses.

EDIT: Now that I look at it the edit button is probably not necessary


1 Like

nice! :smile:

As soon as I figured out how to deal with widgets, I will try this. :wink:

If (or when) I’d tackle this
 I’d start by delegating the actual email sending to services like Mandrill. Following Kirby’s docs and try to create an adaptor to communicate with Mandrill’s API.

The hard (or fun) part would be figuring out how to integrate the users from Kirby account system like @carstengrimm mentioned. Statistics/widgets would also be cool.

Totally different approach I reckon @andi242 
 You’ve got a long way for sure
 Kudos :smile:

1 Like

What problems would you see in integrating kirby users? But I agree that using a service provider would be the more reliable solution. I actually started writing a sendgrid adapter yesterday :smile:

So, @andi242 what do you think?

1 Like

Thanks, @rhawbert :smiley:

I never heard of Mandrill, but it appears to be a more direct approach than MailChimp itself.

I (tried to) develop this Kirby integration, just because of privacy concerns of the customer (a.k.a. friend of mine).
He preferred the direct integration, without having to hand over the newsletter recipients email addresses to a ‘third party’.
That’s a little bit of a paranoia, since they use gmail ever since, but who am I to judge? :wink:
In addition: any mail-footer-advert is not acceptable.

The Mandrill approach is more reliable, though. To be totally honest, I have my concerns of sending the emails via php scripts in the background, because one does not have any control of aborting, etc. the process.

What came up my mind in the last few days of intense Kirby-forum-time:

  • have a widget to start sending emails, as @FabianSperrle proposed earlier
  • perhaps adapting a list of posts via @DieserJonas’ panel field extension (select post to send via mail)
  • have recipients integrated into Kirby as users
  • create a subscribe/unsubscribe form

@FabianSperrle created a small widget on github, which should make it easier for me learning the widget stuff (and it’s cat content!!) :smiley:

this is rough, since I am a php noob. :wink:
And I have no idea on how to control the process that is sending mails.

I think that’s going to be hard to achieve, anyway. You can’t just stop a PHP script from executing externally based on some input
 So if you wanted to be able to abort the process you would have to loop over all recipients in JS and execute the send script on a per-address basis. Then you could just break the JS loop


But then again, all the major providers should accept multiple recipients, so sending 1 or 1000 Mails is just one HTTP request and you can’t cancel that anyway (Sendgrid, again
). And obviously that’s several orders of magnitude faster too (depending on how many emails you actually send).

Let me know if I can be of any help with the widgets or anything else :wink:

Since it would not be possible to leave the page while an js-ajax-send-email-progress-bar-thingy is running, an external provider sounds like the only option to have something reliable.

I remember a wordpress plugin which has a background send, progress and abort functionality, guess I need to dig into that. :smile:

I will come back to your offer, thanks! :smile:

Mandrill is sweet. +1 for a Kirby email list plugin that integrates with Mandrill. And I believe that Mandrill even has a statistics API, in which case there’d be the source of stats to then feed into a Kirby widget - just a thought.

1 Like

@FabianSperrle, I developed a basic modular e-mail setup in K2 awhile ago that utilized sendgrid API. It was very easy to work with, though it never ended up getting used. It allowed the use of different headers, footers and body content and assembled all the html/css before sending. The demo was deploying a single e-mail at a time and wasn’t finished. The idea got shot down before I took it any further. If you’d like I can send you the contents though.

Hey everybody,

I tried to rewrite the plugin from scratch and I guess it’s much better now.
Some of the ideas that were proposed in the forum have been implemented, thank you all. :smile:

Here’s some changes:

  • no more background processing with shell_exec()
  • all recipients are native Kirby users now
  • subscribe and unsubscribe form added
  • all recipients will be added to bcc: in the email (this should be ok for smaller recipients-lists)
  • added a widget (min. req. Kirby 2.0.7) to list the latest 5 children of page blog (please adapt if necessary)

What’s not working until now:
site()->user($username)->delete(); is not working in unsubscribe.php line 29.
I have no idea why.
fixed.

@Luke Sure, that would be great! Do you have it up on GitHub or somewhere?

@andi242:
Thank you very much.

My test on my DEV XAMPP on Win7 first had some errors.
After some time I found, that you sometimes have used the short PHP-Tag <? instead of the longer PHP-Tag <?PHP .
<?= should be <?PHP echo , but I don’t know whether you use this.

If you change that, it can run on all webservers.

1 Like

thank you @HeinerEF I will check this :smile:

Can you specify the PHP/Apache versions?
Since this method is used by kirby itself, I am not sure if this is an issue.

Or is it just the php tag at the beginning of a file?

As you can read at HowTo: Start Kirby development on a PC I use as my DEV system:

  • XAMPP Version 1.8.2-5
  • Apache 2.4.9
  • PHP 5.4.27 (VC9 X86 32bit thread safe) + PEAR

For details look at Example #2 PHP Opening and Closing Tags, the first Note!

But keep in mind that Kirby runs on PHP 5.3 (Requirements).


You use it often within of your php files, not at the beginning.

@anon77445132: You can enable short tags via your php.ini or in your .htaccess.