====== mailResume() ======

''void **mailResume**(string //personID//, int //mailing//, int //time//, [string //C1//, string //C2//, string //C3//, string //C4//, string //C5//])''

This function sends an email during the current questionnaire with a link in order to resume the questionnaire at a later point in time. This is particularly useful when combined with a specific break in multi-wave surveys (''[[:en:create:functions:buttonhide|buttonHide()]]'').

**Note:** The email will only be sent if the participant is already registered in the mailing list.

  * //personID//\\ The personal ID of the addressee who should receive the email. If the participant began the questionnaire after receiving an invitation via mailing, you can fill in ''false'' and a suitable ID will then be automatically determined. Alternatively, the personal ID can be determined using ''[[:en:create:functions:caseserial|caseSerial()]]''.
  * //mailing//\\ (Numerical) mailing ID which should be sent to the participant. In the tab //Reminder/Follow-up Email// for the mailing, the value must be configured to "Reminder or Continuation" as the //Type of Follow-up Email//. Please take the notes below into consideration.
  * //time//\\ Either the delay in email delivery (in seconds: maximum 153900000) __or__ a Unix timestamp, which defines the time until the next email is sent.
  * //C1// to //C5// (optional)\\ If you enter text here (optional), you can use this in the mailing with the help of placeholders ''%custom1%'' to ''%custom5%''. When combined with ''value()'', you can display responses from the current questionnaire in the email, for example. 

===== Tips =====

**Note:** A mailing can be sent multiple times to the same addressees by using ''mailResume()''.

**Note:** In the mailing, the placeholder ''%link%'' is not replaced with a regular personalized link (by calling up the questionnaire in this way it possibly starts again from the beginning). Instead, it is replaced by a direct link to the current questionnaire.  

**Note:** If the participants' email addresses are not known a priori, these have to be collected at the beginning of the first questionnaire so that ''mailResume()'' can be used. Alternatively, using separate questionnaires and the function ''[[:en:create:functions:mailschedule|mailSchedule()]]'' is possible ([[:de:survey:opt-in-live|Multi-Wave Surveys with Self-Selection]]).

**Tip:** There are numerous websites on the internet that can covert a date into a Unix timestamp. For example: [[http://www.unixtime.de/|unixtime.de]]. The PHP [[http://www.php.net/manual/en/ref.datetime.php|Date/Time Functions]] (in particular ''[[http://php.net/manual/en/function.mktime.php|mktime()]]'' and ''[[http://www.php.net/manual/en/function.strtotime.php|strtotime()]]'') are also suited to this purpose. 

**Tip:** If you do not want to send the invitation out on a particular date, but rather after a specific delay, specify the delay because ''mailResume()'' is then able to prevent duplication of emails more efficiently. 


===== Pause Questionnaire =====

In the following example, the participant was invited to the questionnaire via a mailing. A page where the questionnaire is paused is placed in the middle of the questionnaire (''[[:en:create:functions:buttonhide|buttonHide()]]'') and the text "end1" is displayed. The participant receives an email after 24 hours stating he may now fill out the second part of the questionnaire. The link in the email leads him to the next page in the previously interrupted questionnaire. 

<code php>
// If the back button is enabled in the questionnaire
// it should not appear on this page
option('backbutton', false);

// Check how much time has elapsed since the start of the survey
// If this is less than 24 hours (24 * 3600 seconds), the questionnaire will be paused
if (caseTime('begin') < 24 * 3600) {
  text('end1'); // displayed at the end of the first part
  option('resume', true); // prevent indication to resume questionnaire
  option('nextbutton', false); // hide the Next button (pause questionnaire)
  // Send ID 3 mailing tomorrow at the same time (i.e. in exactly 24 hours)
  mailResume(false, 3, 24 * 3600);
} else {
  // Did the participant return after 24 hours? If so, continue questionnaire
  goToPage('next');
}
</code>

Alternatively, you can also check the time elapsed since the the page was first accessed (and thus the time since the email was prepared):

<code php>
// Deactivate the back button as required
option('backbutton', false);

// Save the time the page was first accessed
// Due to isset() und registerVariable(), the block is only executed for the first time
if (!isset($timeBreak1)) {
  // Save the time
  $timeBreak1 = time();
  registerVariable($timeBreak1);
  // Prepare email
  // Send ID 2 mailing in exactly 14 days
  mailResume(false, 3, 14 * 24 * 3600);
}

// Check how much time has elapsed since the page was first accessed 
// Pause, if this is less than than 14 days (14 * 24 * 3600 seconds)
if (time() - $timeBreak1 < 14 * 24 * 3600) {
  text('end1'); // displayed at the end of the first part
  option('nextbutton', false); // hide Next button (pause questionnaire)
} else {
  // Perhaps the progress bar should be adjusted?
  option('progress', 0);
  // Did the participant return after 14 days? If so, continue questionnaire
  goToPage('next');
}
</code>


===== Emailing the Project Manager =====

The function ''mailResume()'' can be "misused" to inform the project manager about incoming questionnaires.  Therefore, it is necessary to import the project manager's email address into the list of contacts ([[:en:survey:mailing|Send Mailings]]). It is essential that the email address imported is not //anonymous//. 

The address entry's personal ID can then be determined from the list of contacts. This is displayed when the mouse is placed over the address entry or when it is opened for editing. In the example, the person ID "ABCDE123" is used. 

If an additional mailing (number 3) was created, the following PHP code informs that a partipant has reached the current page in the questionnaire. 


<code php>
mailResume('ABCDE123', 3, 0);
</code>