IMHO creating a class file on the fly and putting it in the site's files folder is not really a good idea, especially for production sites.

The files folder is not normally in version control, and I am often running into the problem of it missing when I switch developer environments. In general, the files folder just isn't reliable.

Especially since currently, for some reason, Drupal will try to include the generated sites/default/files/mailsystem/ file on every page, causing a fatal error if it is missing, but that is for another issue.

I get that it might be the best way to generate and save the file, but there should at least be another way to include the file, such as maybe the sites/all/libraries folder, or a custom module folder?

There may already be a way to do this, but its just not documented?

If I can figure this out I'll make a patch.


Everett Zufelt’s picture

I have a site with the files dir outside of the drpalroot. This lead to a require() error when an attempt is made to load the class. Also, the files are not in version control. It would be nice if there was an option to download the file from the UI, as the ability to generate it there is great.

To fix:
1. copied the file from .../files/mailsystem/
2. place in a custom module's includes dir and .info file using
files[] = includes/
remove original file from {registry} table
DELETE FROM registry WHERE name='[appropriate-name]' AND module='mailsystem';
drush cc all

nickgs’s picture

605 bytes


I agree. I've hit this problem recently and it is a pretty violent crash when the generated file is not present or accessible. I wonder if it makes sense to generate a custom module from this module as you suggested. At the very least maybe generate a custom module and make it downloadable with documentation on how to add it to your site.

Everett, I've followed your fix and it works great. Attached is the module I created based on your guidelines. Hopefully this can serve as a reference for anyone else that hits this.



Les Lim’s picture

FWIW, the 7.x-3.x branch should eliminate the need for writing PHP files entirely.

topham’s picture

As someone who just hard-crashed a production server environment: Yes, Please Fix this process!

bkonetzny’s picture

This also breaks when s3 is the default filesystem. Classes generated there won't be autoloaded at all. Looking forward for a fix in the 3.x branch.

TravisCarden’s picture

Status: Active » Closed (duplicate)

As @Les Lim mentions, this problem is completely eliminated in the 3.x branch. See #1508104: [PATCH] Replace dynamically generated class with delegation. The new 3.0-alpha1 is only two commits different from the stable 2.x release and appears to function identically. I'm throwing my hat in that ring. Given the lack of movement here, I'm marking this as a duplicate.

ptmkenny’s picture

@TravisCarden Ok, glad to know it's fixed in 3.0-alpha1, but please link to the issue that this one is a duplicate of.

bonus’s picture

Issue summary: View changes
1.69 KB

Above solution as a patch to the 7.x-2.x branch

paolomainardi’s picture

Patch updated to the mailsystem 2.34 version.

webpotato’s picture

Oh I have struggled with this for days. I have tried many of the solutions found here and elsewhere and combinations of modules and template files. Currently I'm trying to set up Simplenews 7.x-1.1 with SMTP 7.x-1.4, HTMLMail 7.x-2.65+13-dev, MimeMail 7.x-1.0-beta4+13-dev, and MailSystem 7.x-3.0-alpha1.

I installed nickgs' html_helper module (#2). I don't think it's doing anything for me except providing a place to store the file other than in /sites/default/files that does not seem to work for me possibly because on my server the files directory is symlinked.

I did this to the registry:

update registry set filename = 'sites/all/modules/html_helper/includes/' where name='HTMLMailSystem__SmtpMailSystem';

and I discovered in the mailsystem.module file a place to "whitelist" alternative mail systems, so I uncommented the whitelist section and added

       'field' => 'name',
       'value' => 'HTMLMailSystem__SmtpMailSystem',

Not really sure that did anything, but my change to the registry allowed me to send a successful HTMLMail test message because HTMLMailSystem__SmtpMailSystem now shows up in the "Test mail sending class" drop-down list and was not there before and it works!

Several times during my ordeal I've gone from fatal error to finely crafted HTMLMail test messages, but I have never been able to send a Simplenews newsletter that HTMLMail ever touched (yes, HTML format set in all FIVE places-- SMTP, general newsletter settings, specific newsletter settings, the input format for the body of the simplenews content type, and MimeMail "Send plain text email only" unchecked). I can get the HTMLMailSystem__SmtpMailSystem combination to send nice HTML test emails, but the MailSystem module refuses to acknowledge (it don't take) when I try to choose SMTP for delivery and HTMLMail for formatting for the "Site-wide default mail system." After submitting, it always just says SMTPMailSystem in both slots.

The same goes for when I try to add aMailsystem custom setting for the Simplenews module. I choose my module, delivery and format methods and click save and nothing. Nothing happens. I don't get any errors, no log entries, no files appear anywhere I can see. I'm not even sure anything is supposed to happen, since it never has, but nothing changes. I feel like I'm being ignored.

As I understand it, HTMLMail says in several places to set something up like HTMLMailSystem__SmtpMailSystem as the "Site-wide default mail system." As I said, it won't let me do that. In MailSystem v2.34, I was also able to get HTMLMailSystem__SmtpMailSystem to show up in all the drop-downs and work only for HTMLMail test messages. In v2.34 there is only one slot for the "Site-wide default mail system," and when I tried to set that to HTMLMailSystem__SmtpMailSystem, it always just came back showing SMTPMailSystem in both slots. In MailSystem v3 there are the two slots to set the "Site-wide default mail system," and I can see HTMLMailSystem__SmtpMailSystem in both drop-downs (realizing that it probably would not work to put HTMLMailSystem__SmtpMailSystem in both slots, but I'll never know because it never takes when I try). Nothing I do changes it from SMTPMailSystem in both slots.

So, I hope someone has an idea of what can be done.

Question: I have a feeling it's the odd configuration of my symlinked files directory that's at the root of this. So, am I correct in my understanding that, if all was working, when I choose a combination of formatter and deliverer, MailSystem writes a file (like in the file system? Is it also supposed to write files there when setting up "custom settings" (in Mailsystem v.3; v2 had what, "additional settings?") to configure for use with modules??? If so, if I could get my hands on those files (the way we were gifted the file in nickgs' module), could I use a similar method to point the module to those configuration files and get HTMLMail to interact with Simplenews? Or another way?

And finally (I know this is long, but I REALLY want to be able to use Simplenews for my clients' newsletters), if there was any way that I could just set up HTMLMailSystem__SmtpMailSystem, through whatever means necessary, as my entire site's default mailsystem, that would be fine with me if that would solve the issue. I'm only a rudimentary php coder and am throwing myself at the feet of you who are more adept. I'm desperate.