Many thanks, managed to get it working. The code is almost identical to the post that I referenced I've only added the processstring line:
Code:
class CustomReplyTo extends PluginBase
{
protected $storage = 'DbStorage';
static protected $description = 'Set reply-to address';
static protected $name = 'CustomReplyTo';
public function init()
{
$this->subscribe('beforeEmail','beforeEmail');
$this->subscribe('beforeSurveyEmail','beforeEmail');
$this->subscribe('beforeTokenEmail','beforeEmail');
// Provides survey specific settings.
$this->subscribe('beforeSurveySettings');
// Saves survey specific settings.
$this->subscribe('newSurveySettings');
}
public function beforeSurveySettings()
{
$event = $this->getEvent();
$event->set("surveysettings.{$this->id}", array(
'name' => get_class($this),
'settings' => array(
'customReplyTo' => array(
'type' => 'string',
'label' => 'Custom Reply-To:',
'current' => $this->get('customReplyTo', 'Survey', $event->get('survey'))
)
)
));
}
/**
* Save the settings
*/
public function newSurveySettings()
{
$event = $this->getEvent();
foreach ($event->get('settings') as $name => $value)
{
$this->set($name, $value, 'Survey', $event->get('survey'));
}
}
/**
* Set From and Bounce of PHPmailer to siteadminemail
* @link https://www.limesurvey.org/manual/BeforeTokenEmail
*/
public function beforeEmail()
{
/* Global one (if you have a global settings array */
$customReplyTo = $this->get('customReplyTo');
/* get the current survey id */
$surveyId = $this->getEvent()->get('survey'); // Survey id as integer
if($surveyId) {
/* Maybe use globalk is empty ( == "") */
$customReplyTo = $this->get('customReplyTo', 'Survey', $surveyId);
}
if(empty($customReplyTo)) {
return;
}
$customReply = LimeExpressionManager::ProcessString($customReplyTo);
$limeMailer = $this->getEvent()->get('mailer');
$limeMailer->AddReplyTo($customReply);
}
}