Sending emails programmatically

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
markS
Forum Members
Forum Members
Posts: 56
Joined: Wed Aug 20, 2008 3:04 pm

Sending emails programmatically

Post by markS »

I have a module which used the CMSMailer module to send emails when it wasn't built-in to the cms. I'd like to upgrade my module to use the built-in mailer functionality rather than needing to load a deprecated module.
As it's still just a wrapper around phpmailer, I am thinking that it's probably just a question of initialising differently and then I can reuse most of the existing code?

I have had a search around and can't see any example code or notes on this, can anyone point me in the right direction or at a module which has updated in this way?

Thanks,

Mark.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1258
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Sending emails programmatically

Post by DIGI3 »

I'm not positive, but I think CGBetterForms (and now its fork, SmartForms) does this.
Not getting the answer you need? CMSMS support options
markS
Forum Members
Forum Members
Posts: 56
Joined: Wed Aug 20, 2008 3:04 pm

[Solved] Re: Sending emails programmatically

Post by markS »

Thank you, that's incredibly helpful! I reviewed the SmartForms module and found the answer.

For future reference, it appears that you simply need to replace the call to CMSMailer with the following:

Code: Select all

$mailer = new \cms_mailer;
Then you can carry on as before. A quick tested example:

Code: Select all

$mailer = new \cms_mailer;
$mailer->AddAddress("test@example.com");
$mailer->SetSubject("This is a test email");
$mailer->SetFrom("test@example.com");
$mailer->SetBody("This is a test email.");
$mailer->IsHTML(false);
$mailer->Send();
Thanks once again.
Post Reply

Return to “Developers Discussion”