Welcome to the LimeSurvey Community Forum

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

Separate Send from and Reply to email addresses

More
5 years 6 months ago #193994 by kclingerman
Thank you all for the feedback, I really like LimeSurvey and I understand Denis' point of view some noob coming in and doing things wrong :P

Thank you for providing a better way for people to accomplish this in the future Denis!

I will try to see if I can get together a plugin which does exactly what I want and share it with the community. I am no expert in PHP but I hope I can contribute!
The following user(s) said Thank You: holch
The topic has been locked.
More
5 years 6 months ago #193995 by DenisChenu
No, @kclingerman : @holch have right. Maybe I was right on the substance, but clearly not on the form.

Otherwise: I criticize the method, not the person. It also happens to me to write stupid and silly things.

For the plugin :
Start with mailSenderToFrom : update it in a new directory inside ./plugins

mailAnswerTo, rename the php file to mailAnswerTo.php
find mailSenderToFrom in the php file to mailAnswerTo, same in config file.

Remove the code here:
github.com/LimeSurvey/LimeSurvey/blob/d6...erToFrom.php#L40-L45

And replace by (for example)

$limeMailer->AddReplyTo(App()->getConfig('siteadminemail'));

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.
The following user(s) said Thank You: holch
The topic has been locked.
More
5 years 6 months ago #194008 by kclingerman
Thank you for the advice!

Can you direct me to some documentation on adding settings to a survey? I would like to be able to set the reply-to address per survey.
The topic has been locked.
More
5 years 6 months ago #194010 by kclingerman
Hey Denis,

I need some advice on this, I am having a lot of trouble with object oriented php lol. In the below plugin storing the plugin settings is fine, but I don't know how to get that into the $limeMailer->AddReplyTo function. Can you please let me know what I am doing wrong?

Thank you!
Code:
<?php
 
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()
    {
      $pluginsettings = $this->getPluginSettings(true);
 
      $event = $this->getEvent();
      $iSurveyID=$event->get('iSurveyID');
      $event->set("surveysettings.{$iSurveyID}", 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()
    {
        $emailsmtpuser = Yii::app()->getConfig('emailsmtpuser');
        if(empty($emailsmtpuser)) {
            return;
        }
        $limeMailer = $this->getEvent()->get('mailer');
    $limeMailer->AddReplyTo($this->get('customReplyTo', 'Survey', $event->get('survey')));
        $this->getEvent()->set('updateDisable',$updateDisable);
    }
}
The topic has been locked.
More
5 years 6 months ago #194022 by DenisChenu
You have to get the current sid if exist.

See : www.limesurvey.org/manual/BeforeSurveyEmail

After
Code:
$this->get('customReplyTo', 'Survey', $surveyId);
give you the value set.

If you need a global one $this->get('customReplyTo');

finally something like this
Code:
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;
        }
        $limeMailer = $this->getEvent()->get('mailer');
        $limeMailer->AddReplyTo($customReplyTo);
    }

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.
The topic has been locked.
More
5 years 6 months ago #194024 by DenisChenu
Move topic to Development :)

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.
The topic has been locked.
More
5 years 6 months ago #194168 by kclingerman
Thank you Denis, this works and helps me understand how to get and use setting values.

The only issue I see now is when the plugin customToken is enabled, my customReplyTo plugin does not show up under the "Simple plugins" menu, only the customToken setting is shown. Is this an issue with limesurvey, or how the plugin was created?


Here is the full source as I am currently using it:
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()
    {
      $pluginsettings = $this->getPluginSettings(true);
 
      $event = $this->getEvent();
      $iSurveyID=$event->get('iSurveyID');
      $event->set("surveysettings.{$iSurveyID}", 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;
        }
        $limeMailer = $this->getEvent()->get('mailer');
        $limeMailer->AddReplyTo($customReplyTo);
    }
}
The topic has been locked.
More
5 years 6 months ago - 5 years 6 months ago #194218 by DenisChenu

kclingerman wrote: The only issue I see now is when the plugin customToken is enabled, my customReplyTo plugin does not show up under the "Simple plugins" menu, only the customToken setting is shown. Is this an issue with limesurvey, or how the plugin was created?

Unsure,

can be a LimeSurvey issue.

You mean you have only one Simple plugin settings shown ?

I think there are an issue in you code.
Code:
$oEvent->set("surveysettings.{$this->id}", array(

and not
Code:
$event->set("surveysettings.{$iSurveyID}", array(

Because you muts add settings for YOUR plugin.

It's an issue in the core plugin
github.com/LimeSurvey/LimeSurvey/blob/4c.../customToken.php#L85

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: 5 years 6 months ago by DenisChenu.
The topic has been locked.
More
5 years 6 months ago #194219 by DenisChenu

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.
The topic has been locked.
Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose