Translations of this page:

Table of Contents


void mailSend(string email, int mailingID, [int time], [string link], [string C1, string C2, string C3, string C4, string C5])

void mailSend(string email, int serialmailID, array settings)

The mailSend() function sends the mailing with the mailingID ID to a specified email address straightaway or at a defined point in time. The email address does not have to – in contrast to the mailResume() and mailSchedule() functions – be known in the project's address list beforehand.

  • email
    Email address where the email should be sent to
  • mailingID
    Numerical ID of the mailing to be sent
  • time (optional)
    Either the delay until the mailing is sent (in seconds, maximum 153900000) or a Unix timestamp that defines the time when it should next be sent.
  • link (optional)
    URL used for the %link% placeholder in the mailing. If no URL is specified, the URL to the questionnaire is used without further specification of a questionnaire.
  • C1 to C5 (optional)
    If you have specified text here (optional), you can use this text in the mailing with the help of placeholders %custom1% to %custom5%. When used with value(), you can, for example, display responses from the ongoing interview in the email.
  • settings (optional)
    If an array is passed as third parameter, the further settings are taken from this array. The following keys are possible:
    • 'sendtime' – corresponds to the parameter time
    • 'update' – SBy default an email is sent with every call of mailSend(). If there is a value for 'update' and an e-mail has already been scheduled for sending (not yet sent) in the survey project with mailSend(), which contains the same value for 'update', then the sending date and all data will be updated instead of preparing another e-mail. For example, if you only want to send one e-mail per interview, then use e.g. 'update' => caseToken().
    • '%link%' – corrsponds to the parameter Link
    • '%custom1%' to '%custom5%' – Content for the placeholders of the same name in the serial mail
    • 'attach' – variable ID (string) or several identifiers (array) of uploaded files (question of type “upload file”), which should be attached to the e-mail. Specify a key in the array to specify the file name for the attachment.


  • A specific mailing can only be sent to a specific email address once per interview with the mailSend() function.
  • A maximum of 20 emails can be sent during an interview using mailSend().

Example 1

A colleague's email address should be requested in the interview, but not saved. An invitation should be sent to this email address with a reference to the current interview (case number CASE).

Note: This use case is usually easier to implement with a question of type Send Email to a Personal Contact and without any PHP code. Here only an alternative solution using mailSend() is shown.

In order to get the email address, an HTML input field is put on page 5 in the questionnaire.

  Colleague's email address:
  <input type="text" name="email_colleague" style="width: 160px" />

On the next page in the questionnaire (no later!), the specified email address is read using readGET() and the mailing with the ID 2 will be sent to this email address. The current case number is attached in the URL to the questionnaire as a reference.

$email = readGET('email_colleague', false);
if (trim($email) !== '') {
  $link = ''.caseNumber();
  mailSend($email, 2, 0, $link);

Example 2

A respondent fills out a test, the point value was calculated in variable $points and is to be sent now together with the participant identification (SERIAL) to a Mailadresse, so that the researcher is informed automatically about terminated tests.

For this purpose a serial mail (ID 1) was created under Send invitationsSerial mails, which has among others the following contents.

respondents: %custom1%
Test result: %custom2%

On the last page of the questionnaire the following PHP code would now be placed under the calculation of the points value ($points) to send the result to

mailSend('', 1, 0, ZERO, caseSerial(), $points);
en/create/functions/mailsend.txt · Last modified: 05.09.2020 13:26 by sophia.schauer
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki