Samuli Natri
Jul. 06, 2012
Updated: Sep. 28, 2016
21
By Samuli NatriJul. 06, 2012
(Updated: Sep. 28, 2016)
21

How To Create Newsletters With Simplenews (Drupal Tutorial)

How to create cron driven Newsletters using Simplenews module.

Creating the newsletter

  • First define a test email address for testing purposes in here: /#overlay=admin/config/services/simplenews/settings



Then create a newsletter:

  • Go to /#overlay=node/add/simplenews
  • Fill in the basic information:

  • Save

Now you have a newsletter to send:

  • Hit the Newsletter tab and you see this:

  • Hit Submit and you will receive this kind of email in your test email address:

Configuring the newsletter

Default settings

You can change the default settings, like:

- default format
- test email address
- sender information 
- confirmation email templates
- number of newsletters to send per cron run etc..


for your newsletters in here: /#overlay=admin/config/services/simplenews/settings (see the tabs also)

Newsletter categories

You can add categories and change their settings, like:

- if new user is automatically subscribed to newsletters with that category
- is confirmation emails sent when (un)subscribing etc..


in here:/#overlay=admin/config/services/simplenews

Created newsletters

Created newsletters can be found here: /#overlay=admin/content/simplenews

Using templates

First select the theme you like to use to render the emails in /#overlay=admin/config/system/mailsystem



There are 4 template files you can override in sites/all/modules/simplenews/theme:

- simplenews-block.tpl.php
- simplenews-multi-block.tpl.php
- simplenews-newsletter-body.tpl.php
- simplenews-newsletter-footer.tpl.php


Just copy them to your theme templates folder (like themes/bartik/templates) and edit them.

Sending HTML mails

Basic settings

  • Go to /#overlay=admin/config/system/mailsystem
  • Under New Setting select Mail > Simplenews module and save settings.

Now you can select only Simplenews module to use HTMLMailSystem under Simplenews module class.

  • Save settings.

Change your default format to HTML for all your newsletters in #overlay=admin/config/services/simplenews/settings
AND/OR
for certain category in /#overlay=admin/config/services/simplenews. Edit the default category if you are using it!

Changing the newsletter

Now if you edit your newsletter and add html to it in /#overlay=admin/content/simplenews

it will show in the email:

Also HTML in template files (simplenews-newsletter-body.tpl.php and simplenews-newsletter-footer.tpl.php) will show now.

HTML Mail template

To edit the HTML Mail template that wraps the simplenews templates, copy the htmlmail--simplenews.tpl.php file from sites/all/modules/htmlmail to themes/bartik/templates.

  • Go to /#overlay=admin/config/system/htmlmail and select Bartik as
    Email theme

Setting up the cron

Your service provider might limit the number of emails you can send so go to /#overlay=admin/config/services/simplenews/settings/mail to change that. Let's say the limit is 1000 mails per hour, so you might want leave space for other emails too and change the cron throttle to 500:

Now just set up a cron with your service provider (it's recommended not to use poormanscron). Setup depends on the software but here's one example using CPanel 11:

  • Go to Advanced / Cron jobs:

  • Add new Cron Job:
  • Read the instructions and ask the service provider how to do this if you're not certain, but it probably goes close to this regardless of the system:



The command is php /home/u /public_html/cron.php >/dev/null 2>&1

u is the account name
public_html is the root of your drupal install
cron.php is your drupal cron file
>/dev/null 2>&1 prevents you to get emails when cron runs

You might want to leave the blue part away and provide an email for testing purposes:



An easy way to test the cron is to create a simple file in public_html/test.php and write a mailing function to it: mail("yourmail@gmail.com","test","test"); and make the cron run every minute with a job like this: php /home/u /public_html/test.php

You should also get some debug data if your provided an email in CPanel 11.

Subscribing existing users

You can use this sql code to subscribe all users to a newsletter category:

Make all subscribers:

insert into simplenews_subscriber(activated, mail, uid)  select 1, mail, uid from users where uid not in (select uid from simplenews_subscriber) and uid > 0;


Subscribe them to a particular newsletter category:

insert into simplenews_subscription(snid, tid, status, timestamp, source) select snid, 1 , 1, unix_timestamp(), 'manual' from simplenews_subscriber where snid not in (select snid from simplenews_subscription);


Notice the red 1 . That's the id number of your newsletter category.
(Hover mouse over a category in here to see it: /#overlay=admin/config/services/simplenews)

You can run these in phpmyadmin for example:
- Go to http://yoursite.localhost:8082/phpmyadmin
- Select your site database
- Hit Sql
- Run the Queries separately:



So now you should be able to create cron driven full HTML newsletters.

Versions used

Drupal http://ftp.drupal.org/files/projects/drupal-7.14.tar.gz
Simplenews http://ftp.drupal.org/files/projects/simplenews-7.x-1.x-dev.tar.gz
Mail System http://ftp.drupal.org/files/projects/mailsystem-7.x-2.34.tar.gz
HTML Mail http://ftp.drupal.org/files/projects/htmlmail-7.x-2.65.tar.gz

Comments

Many thanks.  I was getting nowhere trying to follow the Simplenewsmodule's instructions for sending HTML newsletters, but yours are very easily followed and I've cracked it - all working smoothly.

I now want to install Simplenews on a Drupal 6 site.  I don't suppose you have a simple guide for that...

I have used Simplenews for D6 but I can't remember how different it was.. compared to D7 version. But to your question, no I haven't got tutorial for it. Next time I do newsletter related stuff, I propably do a video for D8 (or D7).

Good Tutorial.

i ddint get the mail when i click on the subscribe button.
and also didnt get the mail when i fill up the mail without login.
i have allready give the permission for that

What a great help and fast workaround. Saved me loads of time and works great.

Recently I had some problems when sending e-mails with simplenews newsletter module for Drupal. While this is a very good module, sometimes made Drupal cron to fail and stuck. I also wanted full control on sending mails and to avoid some of the limitations of Drupal cron timings. Since I didn't have the time to enhance the simplenews module I did this script to be sure that my mails are sent. This script needs simplenews newsletter module and Drupal in order to work. It has been tested with Drupal 7 (but should work on any version) and simplenews 7.

The script works out of drupal and speaks to the database so its better for performance and mail control. You can set the time step and the mails it sends every time based on your server sending limits. At the end logs any bad mails. For me it is the solution for sending my newsltters.

You can learn more and get the script from

http://tecorange.com/content/mail-send-addon-drupal-simplenews-newsletter

is it possible to categorizing news letter? Means In my site there are 4 types of user and I want to allow them to make the selection of the news they want to receive by email.

Give Subscribe to newsletters permission to roles you want to be able to subscribe newsletters. After that they can subscribe/unsubscribe newsletters from their profile page.

already done that,
But requirement a bit litle different , let me explain it briefly.I have four types of user in the site Press, Subadmin,Normal user.They all have separate privileges list according to their roles.But I want to send news realted to press only press users , other suscriber not able to get that.Or when I send newsletter for normal users press users not able to get that.

Now my question is that is it possible?With simplenews. BTW your tutorial helped me a lot in adding newsletter feature in my site.So BIG THANKS to you guys,cheerz

:)

Issue solved but can you tell me why my mails are limited to test email site only?Every time when when i create news letter and send it to test mail address it works perfectly but in the turn of subscriber they get nothig.Till l am looking for the solution.If I found it then i put the reply here soon.Thanks

Add new comment