General Info

General Info

Postby TECOrange » Sun Jul 28, 2013 8:20 am

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.

How it works

You only need the php file and a form that will initiate it plus a custom unsubscribe page. The script uses simplenews newsletter database tables, users, newsletter categories etc. The only thing you have to do is to disable the simplenews newsletter spool cron from Drupal cron in order to avoid having both this tool and Drupal cron sending mails or publish your newsletter but choose not to send them from Simplenews/Drupal interface. You can easily dissable simplenews cron with the Elysia Cron module for Drupal. Users will continue to subscribe/unsubscribe using simplenews newsletter module and you will create the newsletters the usual way. The script works with multiple newsletter categories and every time processes the latest newsletter that has not been sent. After you sent the newsletter, there is nothing else you need to do, spool tables are cleared and newsletter will be marked as sent in your Drupal site. When you are ready to send just call this php file with form submission (see form_example.html). This form will post a username and password (for extra security) to the php file and the process will start.

The custom unsubscribe page

Since we are sending e-mail oustide Drupal and Simple news framework we create a new unsubscribe link that is sent to all users. You can use the unsubscribe.php as example or as is. Simplenews unsubscribe functions still work as well but we need this file/url since we create a new type of unsubscribe URL that is send with mails. You have to declare the path for your new unsubscribe page ine the main php file and also set some settings in unsubscribe.php or how you will name it. You can even copy the php code to a Drupal page -you have to enable php in text editor from Drupal modules/settings- in order to have site-wide look and feel.

When sending mails you should not close the sending browser window. The page refresh it’s self in order to send the number of mails every some seconds based on your settings. After every iteration you will see the results (number of iterations, remaining e-mails), countdown to next iteration and any mail errors at the end. If you close the window before the process ends and resubmit the initiation form thew script will resumeto send last newsletter (in version 1.2 and above).

Settings - Instalation

In the main php file you will have to set a few things, like the database connection details for your Drupal installation and username and password to run the script plus the stepping for mailing (how many mails every how many seconds will be sending) and the unsubscribe URL.

In your unsubscribe page you just have to set database connection details.

In your form (the php script should be called from a form) set the form action URL to mach your renamed php file and submit the username and password you have set in php file. There is a footer text field in the form. You can add there the urls for online view of message. You can use the drupal node URL of the newsletter you will send.

This form can be added as a Drupal page that only admins have access (enable full HTML at Drupal text editor) so you can send your e-mails from your Drupal admin site.

After you do your settings put you form somewhere (even in your computer, or as a secured Drupal page -unpublished, available only to admins-), upload the php file set the unsubscribe page and you are done.


To test the script, the simplest way is, to create a test newsletter category add a few e-mail addresses as subscribers, create a newsletter in this category, all with simplenews newsletter module and Drupal. Then send your newsletter with the initiation form and this php script.

If at some point your server keeps giving you a 500 error, it can be an e-mail address error. Set $debug_error_mail=’1’ in the main php file in order to mark as error the next email in que and then set it back to’0’ to see if you can now proceed. (version 1.3)

Securtiy Tips

You should have no security issues with this sript as it runs outside Drupal, but here are some thing you should do.

-Rename the php file and do not add a public link to it
-Set script username and password in php file
-Add the initiation form to a Drupal page available only to admins, it can be an unpublished page.

Even if someone runs the script, will just sent an unsent newsletter. If all your newsletters have been sent nothing will happen (probably) :-)

Get it from ... ews/files/
View more at ... newsletter

This is a free script from provided “as is” without any kind of warranty. If you think this is good visit share it, subscribe to newsletter or follow at twitter to find a lot of useful things around Web and Mobile Development, Project Management, SEO, SEM and more :-)

For more details about this script and support visit the mail send addon for drupal Simplenews newsletter page.
Site Admin
Posts: 41
Joined: Sun Jul 17, 2011 4:59 pm

Return to Mail Send Addon for Drupal Simplenews Newsletter

Who is online

Users browsing this forum: No registered users and 1 guest