Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Automatic Token Generation/Email

Automatic Token Generation/Email 2 years 10 months ago #69461

  • burmat
  • burmat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Good afternoon LimeSurvey users/devs. First let me start by saying I am new to LimeSurvey, but I am enjoying my time customizing and tweaking it for the need of my company. You guys are hard workers and created a great product that users like myself appreciate.

While I did search to find an answer to my question, my answer seems spread out throughout the world wide web and I would rather build something as up-to-date as possible.

I have a database that stores what is sold to customers and when. Everyday, I want to be able to run a script that will query this DB and pull all customers that have bought a product exactly 2 weeks prior. For each of these results (customer name, email, product purchased, etc..) I would like a token to be automatically generated and emailed to the customer. Querying the customer DB and inserting to the token DB is no problem, it's the auto-sending emails that I need ideas for.

I am looking for ideas on where to start. I have no problem creating the scripts to accomplish my goals, I would just like to hear from other users/devs and see if you have something similar or if there is a good place to start.

Thanks again LimeSurvey!
The administrator has disabled public write access.

Re: Automatic Token Generation/Email 2 years 10 months ago #69504

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
I have coded a cronjob script which is run daily and send invitations/reminders to people listed at the token table of a predefined survey.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Automatic Token Generation/Email 2 years 10 months ago #69517

  • burmat
  • burmat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Thanks for your response Mazi! I almost have that wrapped up. Because I have the survey on a different domain and server, I am exporting all of my customers to .CSV, uploading the file to the survey server, and I have my cronjob (almost complete) reading all .CSV files in a directory into the token table.

I don't really know where to start with the automatic emails though... Can you give me some hints on where to look first?

Thanks again,
-Nate
The administrator has disabled public write access.

Re: Automatic Token Generation/Email 2 years 10 months ago #69523

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
Have a look at /admin/tokens.php ~ line 1400:
"if ($subaction == "email" && bHasSurveyPermission($surveyid, 'tokens','update'))"

At the end of that section the email is send:
"elseif (SendEmailMessage($oMail, $modmessage, $modsubject, $to , $from, $sitename, $ishtml, getBounceEmail($surveyid),null,$customheaders))"

So you should be able to use "SendEmailMessage()" at your cronjob.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Automatic Token Generation/Email 2 years 10 months ago #69526

  • burmat
  • burmat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Great I'll check it out tomorrow when I get back to work. Thanks for the help Mazi!
The administrator has disabled public write access.

Re: Automatic Token Generation/Email 2 years 10 months ago #69555

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
burmat wrote:
Great I'll check it out tomorrow when I get back to work. Thanks for the help Mazi!
You're welcome!

If our hints have been helpful and you enjoy limesurvey please consider a donation to the team .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Automatic Token Generation/Email 2 years 10 months ago #69647

  • burmat
  • burmat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Mazi,
I have a few more questions if you do not mind. How do I retrieve the email template format to use for my .php script? I am using SendEmailMessage() no problem, but I want to be able to customize the email template through LimeSurvey and use it in my custom script. I see a lot of functions that handle the email template and the preparation of the email, but I cannot find a clear cut stem to the source and how to handle them.

If you have any other tips or pointers on where I should look first, I would be very grateful.

- Nathan
The administrator has disabled public write access.

Re: Automatic Token Generation/Email 2 years 10 months ago #69649

  • burmat
  • burmat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Edit:

I think I have found what I was looking for. The table that the email templates are stored in is 'lime_surveys_languagesettings' (tricky name) and I found it by looking through /admin/editemailtemplates.php (look at $esquery). I don't quite know how I am going to handle it but I will post back with my results and scripts I built.

Again, any tips would be greatly appreciated.
- Nathan
The administrator has disabled public write access.

Re: Automatic Token Generation/Email 2 years 10 months ago #69651

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5325
  • Thank you received: 296
  • Karma: 249
It is stored at that weirdly namd table because there can be different versions, depending on the language.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
The following user(s) said Thank You: burmat

Re: Automatic Token Generation/Email 2 years 10 months ago #69708

  • burmat
  • burmat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Ahh that clears it up.

Well thanks for the help Mazi. I attached the script I made below for anyone who wants to use/modify/look at it. One thing that I had to disable that I really didn't want to was the $subject encoding within the SendEmailMessage() function in /common_functions.php. I ended up stripping it away because sending an email from the script was making my subject gibberish and would not decode properly. If anyone has any tips on how to solve this problem so that I could put it back, I would be very grateful.

This script is a very rough draft but feel free to do whatever you want with it. Just to be clear, the script will:
- Read a directory that has .csv files in it.
- For every .csv file, it will import the fields into the tokens table and rename the files to .old so keep them but make them invisible to the script in the future
- It will then get the email template and values, and for each person in the tokens table that has not had an email sent, it will email them and update the sent time

!!NOTE #1: My .csv files *DO NOT HAVE HEADERS* and the columns are: firstname, lastname, email, emailstatus, token (automatically generated at the creation of .csv file), language

!!NOTE #2: When you see '< >' insert your own information. Do a search before you run the file for '<' and '>' symbols to verify you got them all.

File Attachment:

File Name: import_csv.rar
File Size: 3 KB
Last Edit: 2 years 10 months ago by burmat.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.128 seconds
Donation Image