BeforeEmail: Difference between revisions
From LimeSurvey Manual
DenisChenu (talk | contribs) ($this->getEvent()->set('body',$body); and not get) |
DenisChenu (talk | contribs) m (token : null) |
||
(7 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
The event receives the following information: | The event receives the following information: | ||
* mailer : The mailer object | * mailer : The mailer object | ||
* type : Email type : | * type : Email type : default is <code>unknow</code>, and deprecated usage of function is <code>deprecated</code> (for example for plugins not updated), partial list: | ||
** Token email (beforeTokenEmail) | |||
*** <code>invite</code>, | |||
*** <code>remind</code>, | |||
*** <code>register</code>, | |||
*** <code>confirm</code>, | |||
** Survey email (beforeSurveyEmail) | |||
*** <code>savesurveydetails</code> (during survey or by admin), | |||
*** <code>admin_notification</code>, | |||
*** <code>admin_responses</code>, | |||
** Other email | |||
*** <code>passwordreminderadminuser</code>, | |||
*** <code>addadminuser</code>, | |||
*** <code>mailsendusergroup</code> | |||
* subject : Email subject | * subject : Email subject | ||
* to : Recipient(s) with format <code><nowiki>[email,name]</nowiki></code> | * to : Recipient(s) with format <code><nowiki>[email,name]</nowiki></code> | ||
Line 18: | Line 31: | ||
* model : null | * model : null | ||
* updateDisable : array | * updateDisable : array | ||
* token : null | |||
'''Possible output''' | '''Possible output''' | ||
Line 28: | Line 42: | ||
* from : From email and name | * from : From email and name | ||
* bounce : Return-Path | * bounce : Return-Path | ||
* send : If true Limesurvey will send the email. Setting this to false will cause Limesurvey to assume the mail has been sent by the plugin. | * send : If true Limesurvey will send the email. Setting this to false (strict comparison) will cause Limesurvey to assume the mail has been sent by the plugin. | ||
* message : If send is | * message : If send is false and action return a message : the message to be shown | ||
* error : If set and "send" is | * error : If set and "send" is false, log the error as failed email attempt. | ||
'''Usage of mailer''' | '''Usage of mailer''' | ||
The plugin offer as input the mailer object, then you can access and set mailer variables. For example to get the Body before you can use rawBody variables. Since mailer have a public function to do own replacement, you can update the raw body and do the replacement after. | The plugin event offer as input the mailer object, then you can access and set mailer variables. For example to get the Body before you can use rawBody variables. Since mailer have a public function to do own replacement, you can update the raw body and do the replacement after. | ||
A sample code can be : | A sample code can be : | ||
Line 48: | Line 62: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Check '''mailSenderToFrom''' core plugin for another usage of mailer to set the sender, the Response-To and the From-To. | Check '''mailSenderToFrom''' core plugin for another usage of mailer to set the sender, the Response-To and the From-To. The whole class are [https://github.com/LimeSurvey/LimeSurvey/blob/master/application/core/LimeMailer.php LimeMailer] and extend [https://github.com/LimeSurvey/LimeSurvey/blob/master/application/third_party/phpmailer/src/PHPMailer.php PHPMailer]. | ||
'''Example''' | '''Example''' | ||
* [https://gitlab.com/SondagesPro/mailing/noMailToExample noMailToExample] | * [https://gitlab.com/SondagesPro/mailing/noMailToExample noMailToExample] | ||
* [https://github.com/LimeSurvey/LimeSurvey/ | * [https://github.com/LimeSurvey/LimeSurvey/tree/master/application/core/plugins/mailSenderToFrom mailSenderToFrom] | ||
* [https://github.com/Xites/LS_mailDKIM mailDKIM] | |||
* [https://github.com/Xites/LS_mailEmbedImages mailEmbedImages] | |||
'''See also''' | |||
* [[beforeSurveyEmail]] | |||
* [[beforeTokenEmail]] | |||
[[Category:Plugins events]] | [[Category:Plugins events]] |
Latest revision as of 18:14, 21 July 2022
Hint: This features is available starting in version 4.0.0
Usage
This event can be used each time an email not related to a survey is send.
Input
The event receives the following information:
- mailer : The mailer object
- type : Email type : default is
unknow
, and deprecated usage of function isdeprecated
(for example for plugins not updated), partial list:- Token email (beforeTokenEmail)
invite
,remind
,register
,confirm
,
- Survey email (beforeSurveyEmail)
savesurveydetails
(during survey or by admin),admin_notification
,admin_responses
,
- Other email
passwordreminderadminuser
,addadminuser
,mailsendusergroup
- Token email (beforeTokenEmail)
- subject : Email subject
- to : Recipient(s) with format
[email,name]
- body : Email body content
- from : Sender (From)
- bounce : The Sender (Return-Path)
- survey : null
- model : null
- updateDisable : array
- token : null
Possible output
The following information can be set in the event:
- updateDisable : if plugin use mailer to update other parts, allow to disable update by default action
- subject : Email subject
- body : Email body content
- to : Recipient(s) in
[[email,name]]
format - from : From email and name
- bounce : Return-Path
- send : If true Limesurvey will send the email. Setting this to false (strict comparison) will cause Limesurvey to assume the mail has been sent by the plugin.
- message : If send is false and action return a message : the message to be shown
- error : If set and "send" is false, log the error as failed email attempt.
Usage of mailer
The plugin event offer as input the mailer object, then you can access and set mailer variables. For example to get the Body before you can use rawBody variables. Since mailer have a public function to do own replacement, you can update the raw body and do the replacement after.
A sample code can be :
$mailer = $this->getEvent()->get(mailer);
$rawBody = $mailer->rawBody;
// Clean up code
$oPurifier = new \CHtmlPurifier();
$rawBody = $oPurifier->purify($rawBody);
$body = $mailer->doReplacements($rawBody);
$this->getEvent()->set('body',$body);
Check mailSenderToFrom core plugin for another usage of mailer to set the sender, the Response-To and the From-To. The whole class are LimeMailer and extend PHPMailer.
Example
See also