0 votes
ago in SoSci Survey (dt.) by s335352 (110 points)

Hallo Zusammen,

Ich möchte für meine Tagebuchstudie den Versand von insgesamt 20 Fragebögen automatisieren. Über insgesamt 10 Werktage werden pro Tag 2 Fragebögen versendet an eine E-Mail, dir vorher per Opt-In gespeichert wurde. Ein Fragebogen soll um 12:00 Uhr, der andere um 16:00 Uhr versendet werden. Jeweils 2 Stunden nach dem Versand soll zudem eine Erinnerung versendet werden.

In meinem Testlauf funktionierte bisher die Opt-In Anmeldung problemlos. Der Knackpunkt kommt bei der korrekten Versendung der 2 täglichen Fragebögen.

Am Ende der demographischen Daten wählen die Teilnehmenden den "Start" der täglichen Fragebögen. Entweder am nächsten oder Übernächsten Montag.

Mein Code dafür sieht wie folgt aus:

$startKW1 = date("d.m.Y.", strtotime("next Monday"));
$endKW1   = date("d.m.Y.", strtotime("+11 days", strtotime($startKW1)));
$startKW2 = date("d.m.Y.", strtotime("next Monday +7 days"));
$endKW2   = date("d.m.Y.", strtotime("+11 days", strtotime($startKW2)));


replace('%tag1%', $startKW1);
replace('%tag2%', $endKW1);
replace('%tag3%', $startKW2);
replace('%tag4%', $endKW2);

auf der Seite direkt danach im Fragebogen kommt dann der (recht lange) Code, um die Fragebögen zu automatisieren: 

if (value('OP02') == 1) {
    $day01 = date('d.m.Y', strtotime("Next Monday"));
} elseif (value('OP02') == 2) {
    $day01 = date('d.m.Y', strtotime("Next Monday + 7 Days"));
}

$day02 = date('d.m.Y', strtotime($day01 ."+ 1 Day"));
$day03 = date('d.m.Y', strtotime($day01 ."+ 2 Day"));
$day04 = date('d.m.Y', strtotime($day01 ."+ 3 Day"));
$day05 = date('d.m.Y', strtotime($day01 ."+ 4 Day"));
$day08 = date('d.m.Y', strtotime($day01 ."+ 7 Day"));
$day09 = date('d.m.Y', strtotime($day01 ."+ 8 Day"));
$day10 = date('d.m.Y', strtotime($day01 ."+ 9 Day"));
$day11 = date('d.m.Y', strtotime($day01 ."+ 10 Day"));
$day12 = date('d.m.Y', strtotime($day01 ."+ 11 Day"));

//Diary IDs
$diary_011 = 2; $diary_012 = 13; $diary_021 = 4; $diary_022 = 14;
$diary_031 = 5; $diary_032 = 15; $diary_041 = 6; $diary_042 = 16;
$diary_051 = 7; $diary_052 = 17; $diary_061 = 8; $diary_062 = 18; 
$diary_071 = 9; $diary_072 = 19; $diary_081 = 10; $diary_082 = 20; 
$diary_091 = 11; $diary_092 = 21; $diary_0101 = 12; $diary_0102 = 22;

//Daily Erinnerungen IDs
$Ediary_011 = 23; $Ediary_012 = 33; $Ediary_021 = 24; $Ediary_022 = 34;
$Ediary_031 = 25; $Ediary_032 = 35; $Ediary_041 = 26; $Ediary_042 = 36; 
$Ediary_051 = 27; $Ediary_052 = 37; $Ediary_061 = 28; $Ediary_062 = 38; 
$Ediary_071 = 29; $Ediary_072 = 39; $Ediary_081 = 30; $Ediary_082 = 40; 
$Ediary_091 = 31; $Ediary_092 = 42; $Ediary_0101 = 32; $Ediary_0102 = 42;

//Versendung
$MZP_011 = date("H:i", strtotime('12:00.'));
$MZP_012 = date("H:i", strtotime('16:00.'));
$dMZP_011 = date('d.m.Y', strtotime(($day01).'day'));
$dMZP_012 = date('d.m.Y', strtotime(($day01).'day'));
    mailSchedule(false, $diary_011, strtotime($dMZP_011 . " " . $MZP_011));
    mailSchedule(false, $diary_012, strtotime($dMZP_012 . " " . $MZP_012));
$EMZP_011 = date("H:i", strtotime('.14:00.'));
$EMZP_012 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_011, strtotime($dMZP_011. " " .$EMZP_011),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_012, strtotime($dMZP_012. " " .$EMZP_012),
        array('status' => 'incomplete'));

$MZP_021 = date("H:i", strtotime('12:00.'));
$MZP_022 = date("H:i", strtotime('16:00.'));
$dMZP_021 = date('d.m.Y', strtotime(($day02).'day'));
$dMZP_022 = date('d.m.Y', strtotime(($day02).'day'));
    mailSchedule(false, $diary_021, strtotime($dMZP_021 . " " . $MZP_021));
    mailSchedule(false, $diary_022, strtotime($dMZP_022 . " " . $MZP_022));
$EMZP_021 = date("H:i", strtotime('.14:00.'));
$EMZP_022 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_021, strtotime($dMZP_021. " " .$EMZP_021),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_022, strtotime($dMZP_022. " " .$EMZP_022),
        array('status' => 'incomplete'));

$MZP_031 = date("H:i", strtotime('12:00.'));
$MZP_032 = date("H:i", strtotime('16:00.'));
$dMZP_031 = date('d.m.Y', strtotime(($day03).'day'));
$dMZP_032 = date('d.m.Y', strtotime(($day03).'day'));
    mailSchedule(false, $diary_031, strtotime($dMZP_031 . " " . $MZP_031));
    mailSchedule(false, $diary_032, strtotime($dMZP_032 . " " . $MZP_032));
$EMZP_031 = date("H:i", strtotime('.14:00.'));
$EMZP_032 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_031, strtotime($dMZP_031. " " .$EMZP_031),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_032, strtotime($dMZP_032. " " .$EMZP_032),
        array('status' => 'incomplete'));

$MZP_041 = date("H:i", strtotime('12:00.'));
$MZP_042 = date("H:i", strtotime('16:00.'));
$dMZP_041 = date('d.m.Y', strtotime(($day04).'day'));
$dMZP_042 = date('d.m.Y', strtotime(($day04).'day'));
    mailSchedule(false, $diary_041, strtotime($dMZP_041 . " " . $MZP_041));
    mailSchedule(false, $diary_042, strtotime($dMZP_042 . " " . $MZP_042));
$EMZP_041 = date("H:i", strtotime('.14:00.'));
$EMZP_042 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_041, strtotime($dMZP_041. " " .$EMZP_041),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_042, strtotime($dMZP_042. " " .$EMZP_042),
        array('status' => 'incomplete'));

$MZP_051 = date("H:i", strtotime('12:00.'));
$MZP_052 = date("H:i", strtotime('16:00.'));
$dMZP_051 = date('d.m.Y', strtotime(($day05).'day'));
$dMZP_052 = date('d.m.Y', strtotime(($day05).'day'));
    mailSchedule(false, $diary_051, strtotime($dMZP_051 . " " . $MZP_051));
    mailSchedule(false, $diary_052, strtotime($dMZP_052 . " " . $MZP_052));
$EMZP_051 = date("H:i", strtotime('.14:00.'));
$EMZP_052 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_051, strtotime($dMZP_051. " " .$EMZP_051),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_052, strtotime($dMZP_052. " " .$EMZP_052),
        array('status' => 'incomplete'));

$MZP_061 = date("H:i", strtotime('12:00.'));
$MZP_062 = date("H:i", strtotime('16:00.'));
$dMZP_061 = date('d.m.Y', strtotime(($day08).'day'));
$dMZP_062 = date('d.m.Y', strtotime(($day08).'day'));
    mailSchedule(false, $diary_061, strtotime($dMZP_061 . " " . $MZP_061));
    mailSchedule(false, $diary_062, strtotime($dMZP_062 . " " . $MZP_062));
$EMZP_061 = date("H:i", strtotime('.14:00.'));
$EMZP_062 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_061, strtotime($dMZP_061. " " .$EMZP_061),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_062, strtotime($dMZP_062. " " .$EMZP_062),
        array('status' => 'incomplete'));

$MZP_071 = date("H:i", strtotime('12:00.'));
$MZP_072 = date("H:i", strtotime('16:00.'));
$dMZP_071 = date('d.m.Y', strtotime(($day09).'day'));
$dMZP_072 = date('d.m.Y', strtotime(($day09).'day'));
    mailSchedule(false, $diary_071, strtotime($dMZP_071 . " " . $MZP_071));
    mailSchedule(false, $diary_072, strtotime($dMZP_072 . " " . $MZP_072));
$EMZP_071 = date("H:i", strtotime('.14:00.'));
$EMZP_072 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_071, strtotime($dMZP_071. " " .$EMZP_071),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_072, strtotime($dMZP_072. " " .$EMZP_072),
        array('status' => 'incomplete'));

$MZP_081 = date("H:i", strtotime('12:00.'));
$MZP_082 = date("H:i", strtotime('16:00.'));
$dMZP_081 = date('d.m.Y', strtotime(($day10).'day'));
$dMZP_082 = date('d.m.Y', strtotime(($day10).'day'));
    mailSchedule(false, $diary_081, strtotime($dMZP_081 . " " . $MZP_081));
    mailSchedule(false, $diary_082, strtotime($dMZP_082 . " " . $MZP_082));
$EMZP_081 = date("H:i", strtotime('.14:00.'));
$EMZP_082 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_081, strtotime($dMZP_081. " " .$EMZP_081),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_082, strtotime($dMZP_082. " " .$EMZP_082),
        array('status' => 'incomplete'));

$MZP_091 = date("H:i", strtotime('12:00.'));
$MZP_092 = date("H:i", strtotime('16:00.'));
$dMZP_091 = date('d.m.Y', strtotime(($day11).'day'));
$dMZP_092 = date('d.m.Y', strtotime(($day11).'day'));
    mailSchedule(false, $diary_091, strtotime($dMZP_091 . " " . $MZP_091));
    mailSchedule(false, $diary_092, strtotime($dMZP_092 . " " . $MZP_092));
$EMZP_091 = date("H:i", strtotime('.14:00.'));
$EMZP_092 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_091, strtotime($dMZP_091. " " .$EMZP_091),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_092, strtotime($dMZP_092. " " .$EMZP_092),
        array('status' => 'incomplete'));

$MZP_0101 = date("H:i", strtotime('12:00.'));
$MZP_0102 = date("H:i", strtotime('16:00.'));
$dMZP_0101 = date('d.m.Y', strtotime(($day12).'day'));
$dMZP_0102 = date('d.m.Y', strtotime(($day12).'day'));
    mailSchedule(false, $diary_0101, strtotime($dMZP_0101 . " " . $MZP_0101));
    mailSchedule(false, $diary_0102, strtotime($dMZP_0102 . " " . $MZP_0102));
$EMZP_0101 = date("H:i", strtotime('.14:00.'));
$EMZP_0102 = date("H:i", strtotime('.18:00.'));
    mailSchedule(false, $Ediary_0101, strtotime($dMZP_0101. " " .$EMZP_0101),
        array('status' => 'incomplete'));
    mailSchedule(false, $Ediary_0102, strtotime($dMZP_0102. " " .$EMZP_0102),
        array('status' => 'incomplete'));

Ich habe für jeden einzelnen Fragebogen eine separate Serienmail erstellt (insgesamt 40, 20 reguläre tägliche Fragebögen und je 20 separate Erinnerungen) die IDs der Fragebögen habe ich oben genannt.

In meinem Testlauf ergibt sich das Problem, dass ich die täglichen Fragebögen + Erinnerungen zu einer falschen Zeit am falschen Tag erhalte (am nächsten Tag, egal ob Montag oder nicht und dann mitten in der Nacht um 02:40 Uhr und um 04:40 Uhr).

Zudem erhalte ich alle 10 Serienmails für 12:00 Uhr oder 16:00 Uhr gleichzeitig und nicht, wie geplant, jeweils eine Serienmail.

Ich stehe grad auf dem Schlauch und weiß nicht, wo hier das Problem liegt.

Bin sehr dankbar über Tipps und evtl. Lösungen.

Vielen Dank!

1 Answer

0 votes
ago by SoSci Survey (359k points)

Ich habe nicht den kompletten Code durchgesehen, aber bereits in den ersten Zeilen wandeln Sie mehrfach zwischen lesbaren Datumsangaben und Unix-Zeitstempeln hin und her. Das ist nicht nur unnötig komplex, sondern verursacht auch Fehler.

$startKW1 = date("d.m.Y.", strtotime("next Monday"));
$endKW1   = date("d.m.Y.", strtotime("+11 days", strtotime($startKW1)));

In der ersten Zeile erzeugen Sie mit strtotime() den Zeitstempel für nächsten Montag. Soweit so gut. Sie könnten noch 00:00:00 ergänzen, damit der Anfang des Tages und nicht die aktuelle Zeit verwendet wird.

Mittels date() wandeln Sie das dann in einen lesbaren Zeitstempel wie z.B. "17.11.2025" um. In der folgenden Zeile verwenden Sie dann strtotime(), um das wieder in einen Unix-Zeitstempel umzuwandeln. An dieser Stelle passiert aber ein Fehler: 17.11.2025 ist für strtotime() nicht sinnvoll lesbar, die Funktion würde eher "2025-11-17" erwarten, weiß also nicht, was genau es machen soll.

Lösung: Bleiben Sie gleich beim Zeitstempel.

$startKW1 = strtotime("next Monday 00:00:00");
$endKW1   = strtotime("+11 days", $startKW1);

Unten dann nochmal dasselbe unten.

$dMZP_011 = date('d.m.Y', strtotime(($day01).'day'));
$MZP_011 = date("H:i", strtotime('12:00.'));
mailSchedule(false, $diary_011, strtotime($dMZP_011 . " " . $MZP_011));

Arbeiten Sie hier ebenfalls mit Zeitstempeln. 12 Stunden sind einfach 12 x 3600 Sekunden.

$dMZP_011 = date('d.m.Y', strtotime(($day01).'day'));

Diese Zeile macht inhaltlich besonders wenig Sinn, denn da soll strototime() versuchen, etwas wie "17.11.2025day" in einen Zeitstempel umzuwandeln. Gehen wir also mal davon aus, dass Sie in $day01 künftig einen Zeitstempel haben, dann..

$dMZP_011 = $day01;
$MZP_011 = 12 * 3600;
mailSchedule(false, $diary_011, $dMZP_011 + $MZP_011);

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...