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

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #193982 by holch
Denis, not everyone is as firm with the plugin system for Limesurvey as you are.

kclingerman needed a quick solution and this is what he found. Might there be a better solution? Obviously, as you have shown. But we should be happy that he was giving back to the community, most people here are only taking.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
4 years 9 months ago #193983 by DenisChenu
Replied by DenisChenu on topic Separate Send from and Reply to email addresses

holch wrote: Denis, not everyone is as firm with the plugin system for Limesurvey as you are.

kclingerman needed a quick solution and this is what he found. Might there be a better solution? Obviously, as you have shown. But we should be happy that he was giving back to the community, most people here are only taking.

Updating LimeSurvey core are always a bad solution.

And here : there are sample clear and easy to adapt.

LimeMailer : 799 lines
mailSenderToFrom : 48 lines

We have an extandable system : we must give good advice on forum not broken advice ... that potentially broke update ...

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.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #193992 by holch

We have an extandable system : we must give good advice on forum not broken advice ... that potentially broke update ...


I agree. But your post doesn't sound like "good advice" but like a grumpy old grandpa... ;-)

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • kclingerman
  • kclingerman's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #193994 by kclingerman
Replied by kclingerman on topic Separate Send from and Reply to email addresses
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.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
4 years 9 months ago #193995 by DenisChenu
Replied by DenisChenu on topic Separate Send from and Reply to email addresses
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.
  • kclingerman
  • kclingerman's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #194008 by kclingerman
Replied by kclingerman on topic Separate Send from and Reply to email addresses
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.
  • kclingerman
  • kclingerman's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #194010 by kclingerman
Replied by kclingerman on topic Separate Send from and Reply to email addresses
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.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
4 years 9 months ago #194022 by DenisChenu
Replied by DenisChenu on topic Separate Send from and Reply to email addresses
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.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
4 years 9 months ago #194024 by DenisChenu
Replied by DenisChenu on topic Separate Send from and Reply to email addresses
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.
  • kclingerman
  • kclingerman's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #194168 by kclingerman
Replied by kclingerman on topic Separate Send from and Reply to email addresses
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.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
4 years 9 months ago - 4 years 9 months ago #194218 by DenisChenu
Replied by DenisChenu on topic Separate Send from and Reply to email addresses

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: 4 years 9 months ago by DenisChenu.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
4 years 9 months ago #194219 by DenisChenu
Replied by DenisChenu on topic Separate Send from and Reply to email addresses

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