I want to send a single mail to a responsible address when a certain event occur in my extension. I had a look to some API (Email, Mailing, MailingAB) but but none of these seem to be the right one. There is an API or a class I can use to send mails?
4 Answers
The Email API extension will have example code for you to use for your extension. Its code is available on github: https://github.com/CiviCooP/org.civicoop.emailapi
Finally I used the following code for send a mail:
$mailParams = array(
'groupName' => '...',
'from' => '...',
'toName' => '...',
'toEmail' => '...',
'subject' => '....',
'text' => ''....,
);
$result = CRM_Utils_Mail::send($mailParams);
You may want to have a look at the extension CiviRules that allows you to configure triggers, conditions, and actions such as sending out an email on a certain event.
-
Thanks Fabian, I'm writing my own extension, so I would like to send an email regardless of the presence of CiviRules extension. I looking for a code example, an API or a Class call, usefull for sending a mail.– marcelloCommented Dec 22, 2016 at 15:35
Take a look at this extension that Sarah Gladstone wrote. It sounds similar to what you're doing and you might be able to get some example code from it.
https://github.com/sgladstone/com.fountaintribe.scheduledcommunication