Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Custom replyto address

  • educaticteced
  • educaticteced's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 months 1 week ago #266080 by educaticteced
Custom replyto address was created by educaticteced
Your LimeSurvey version: 5.6.63
Own server or LimeSurvey hosting: Own server
Survey theme/template: Vanilla
==================
Based in the answers and code shared here [url] forums.limesurvey.org/forum/development/...l-addresses?start=12 [/url] and from the plugin mailSenderToFrom, I'm trying to set a custom replyto address based on a survey field, the point being that the recipients of the notification can simply it "Reply" to reply to a surveynotification and the reply to field will be filled with the user mail. After reading manual.limesurvey.org/BeforeSurveyEmail I'm not entirely sure if this is possible, does anyone has any sugestions on how best implement this? My idea was that the survey administrator would have a setting that would be filled with something like {2314125X213X321} that would point to email field, but I'm no sure on how to do it or if this is even viable.

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
2 months 1 week ago - 2 months 1 week ago #266082 by DenisChenu
Replied by DenisChenu on topic Custom replyto address

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
Last edit: 2 months 1 week ago by DenisChenu.

Please Log in to join the conversation.

  • educaticteced
  • educaticteced's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 months 1 week ago #266094 by educaticteced
Replied by educaticteced on topic Custom replyto address
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://manual.limesurvey.org/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);
    }
}
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose