Welcome, Guest
Username: Password: Remember me

TOPIC: Email One Answer Before Survey Submit

Email One Answer Before Survey Submit 7 months 3 weeks ago #102905

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 203
  • Thank you received: 5
  • Karma: 5
Hi LS Folk,
I have searched hi and low for a script that would allow me to:

1) Capture the results of a single question. (This question is a "report" housed in a Text Display question built using Expression Manager and the answers to many previous questions.)
2) Present the Respondent with a button that will send this report via email to their email address.

I've tried using webformmailer and a couple of others that use a script on my server, but I was hoping there was a way to utilize LimeSurvey's mail functions to accomplish this.

Any advice would be most appreciated.
David
The administrator has disabled public write access.

Email One Answer Before Survey Submit 7 months 3 weeks ago #102906

  • supercosh
  • supercosh's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Thank you received: 9
  • Karma: 1
Hi David

It is not in my knowledge that the mail api from LS can be used directly in a "high-level" manner out of a survey. I would stick to the solution you allready mentioned: Putting in a link like "mailer.php?survey=123456&token=ABCDEF", the mailer.php script then connects to the LS DB, looks up the token in the corresponding survey table, reads out the answer(s) and sends them to the recipient (=participant identifed by email address in the tables).

If you make the script part of the LS app, it could use the classes from LS in order to issue mails with the correct SMTP settings and so on.

Easier ideas, anyone?

Regards,
Gregor
Last Edit: 7 months 3 weeks ago by supercosh.
The administrator has disabled public write access.

Email One Answer Before Survey Submit 7 months 3 weeks ago #102907

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 203
  • Thank you received: 5
  • Karma: 5
Hey - thank you tremendously for your reply.
If you make the script part of the LS app, it could use the classes from LS in order to issue mails with the correct SMTP settings and so on.

It is exactly this which I hope to accomplish, but I haven't the slightest idea of how to go about it.

I would need to attempt some minor formatting for the message as well when it is sent. Also, the the mailer that I abandoned required that the page be refreshed or redirected upon button press. And, I never received my test emails> (#fail).

I'll keep looking for a solution. Thank you.
The administrator has disabled public write access.

Email One Answer Before Survey Submit 7 months 3 weeks ago #102908

  • supercosh
  • supercosh's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Thank you received: 9
  • Karma: 1
Hi David

LS uses SendEmailMessage() internally, the function is found in /application/helpers/common_helper.php. However, you need to load the Yii Framework in order to use that function.

The function then sends an email using the specified configuration from LimeSurvey.

Be also sure to set the parameter $isHtml to true when you like to send formatted mails - otherwise the email body would get flattened to text-only before sending.

Still a simple solution would be to send the message with PHP's mail() function or by using phpmailer (included with LS). In order to have the page not loaded again, you could make the button open the php script in a popup window, and to be nice also display a message that the mail was sent successfully and that the window may be closed now ;-). If popups are not desired, an AJAX implementation would be required.

Regards,
Gregor
The administrator has disabled public write access.

Email One Answer Before Survey Submit 7 months 3 weeks ago #102909

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 203
  • Thank you received: 5
  • Karma: 5
I like your thoughts. I am not a programmer; I have little idea about how to actually "call the script", much less edit it. I guess I would put a form button inside a question's text that calls" the script I have somehow" edited to uses phpmailer.

I have some reading to do! Thanks for your thoughtful replies.
David
The administrator has disabled public write access.

Email One Answer Before Survey Submit 7 months 3 weeks ago #102910

  • supercosh
  • supercosh's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Thank you received: 9
  • Karma: 1
Yes, that's exactly the way to go. Use a "Text display" question, which supports HTML as well as javascript. Build a HTML Form, and put two hidden fields "recipient" and "mailbody" into it - and let the mailbody be filled with the text you allready built with the evaluations. Let the form have "mailer.php" as the form action, and POST as the method and place the "Send E-Mail" Button in the form...

When the from gets submitted to mailer.php, this script does nothing more than sending an email to the recipient parameter with the body parameter.

However, you need to secure the script from being called by anyone who has knowledge of it (spammers). If that's a realistic problem, you could use a simple checksum which is checked in the script. I strongly recommend doing that, but it's not mandatory.

If you need some prof. help in this, you'd be welcome to write me a private message by clicking on my image to the left.

Regards and good luck!
Gregor
The administrator has disabled public write access.

Email One Answer Before Survey Submit 7 months 3 weeks ago #102911

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 203
  • Thank you received: 5
  • Karma: 5
Ahh, I think I understand all but one thing. What is the location of the mailer.php.
Do you literally write <form action="www.mydomain.com/subdirectory/mailer.php?> Method=post?
I might take you up on the prof offer sometime as well.
Thank you again!
Last Edit: 7 months 3 weeks ago by dweisser.
The administrator has disabled public write access.

Email One Answer Before Survey Submit 7 months 3 weeks ago #102913

  • supercosh
  • supercosh's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 25
  • Thank you received: 9
  • Karma: 1
Correct, it would look like that:
  <form method="post" action="/myscripts/mailer.php" target="_blank">
    <input type="hidden" name="recipient" value="PUT-EMAIL-ADR-HERE" />
    <input type="hidden" name="body" value="PUT-TEXTBODY-HERE" />
    <input type="submit" value="Send me the results" />
  </form>

Your script then resides in /myscripts and is named mailer.php (or any other name you like to chose). It should check the input parameters in $_POST (recipient and body) in order to send them using the function mail() of PHP.

Regards,
Gregor
Last Edit: 7 months 3 weeks ago by supercosh.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.163 seconds
Donation Image