emails from website getting rejected from email services

By wizzle - October 26, 2017

I sifted through the CMSB and plugin files to better understand you... and I can see where sendMessage is used in the forum plugin, in the website membership plugin, and on some core CMSB (like user password request).

I did find one instance of mail() being used in a plugin that I have called emailOnApproved. I don't see the plugin on the official Add-On's page so I think it's a small one that has been passed around the forums a bit.  I am actually using 3 instances of this plugin (renamed). 

So 2 questions...

1. even though the function being called is sendMessage, it is currently still using the built-in php mail() protocol because that's what I have selected in the email settings.  Have other people experienced a similar issue with using that protocol? Is switching to smtp generally a better choice anyways? Or does something just seem screwy with my particular web/email host?

2. Would I be safe in the emailOnApproved plugin to just change the line that says

mail($to,$subject,$message,$headers);

to simply

sendMessage($to,$subject,$message,$headers);

or are the parameters different?

Greg Williams

By Dave - October 26, 2017

Hi Wizzle, 

To answer your questions: 

1. even though the function being called is sendMessage, it is currently still using the built-in php mail() protocol because that's what I have selected in the email settings.  Have other people experienced a similar issue with using that protocol? Is switching to smtp generally a better choice anyways? Or does something just seem screwy with my particular web/email host?

CMSB can send mail a variety of ways, but yes the default still calls mail() (through swift mailer).  mail() is just a PHP function that hands off the message to the outgoing mail server that's running on the server.  It does pretty much the same thing as logging in via SMTP but faster.  

It's likely that switching to SMTP won't change anything, but systematically following the advice of your web host is a good way to rule out issues and get further support.  And if in the end, they don't have a reliable outgoing mail server, you'll still use SMTP but just be specifying another provider.

2. Would I be safe in the emailOnApproved plugin to just change the line that says

The parameters are different.  Most of our internal functions have short instructions or examples in the code above where they're defined.  See if you can find sendMessage (search for: function sendMessage) and figure it out.  If you need help let me know!  Post back and let me know how it goes.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

By Dave - October 31, 2017

Hi Wizzle, 

We're not currently using "Background Send", but it's available for plugins and other internal use.  We were going to use it with Newsletter Builder but having thousands of copies of emails in the outgoing mail queue wasn't as efficient as generating the email content on the fly when we were sending them.  So effectively you can ignore that option.

The first step is to find out what your hosts limits are. 

Next, if you're using newsletter builder you can configure the max send speed with these settings at the top of the plugin: 

$GLOBALS['BACKGROUND_SEND_MAX']     = 500; // max messages to send in each batch, eg: If a cronjob runs the script every minute and this is set to 30, you'll send approx 1800 emails an hour
$GLOBALS['BACKGROUND_SEND_WEB_MAX'] = 25;  // max messages to send when calling mailer through web interface, browser sessions can timeout so set this low (example: 25)
$GLOBALS['BACKGROUND_SEND_DELAY']   = 0;   // second to wait after sending each message

I'd just set them to slightly lower than the max.  Other than that, for regular email usage (forum alerts, password reset emails, etc) you should be fine.  But if you need to send a LOT of email very quickly then you'd either need to setup a cron as you suggest and throttle the emails to send slower and/or just find a 3rd party SMTP service and use them.

One issue with rate limited web hosts is that if you're sending a LOT of email and their limits are low it can take days just to send it all out.

Hope that helps!  

Dave Edis - Senior Developer
interactivetools.com