/** * Verschickt eine E-Mail * @param string $subject Betreff * @param array $to Empfänger: array mit Keys = E-Mail und Values = Name; z.B. array("*****@*****.**" => "Max", "*****@*****.**" => "Lisa") * @param string $text Inhalt als Text * @param string $html Inhalt als HTML * @return Anzahl der erfolgreichen Empfängern */ function sendMail($subject, $to, $text, $html, $token, $request) { global $app, $smtpMail, $smtpName; $successful = 0; $message = \Swift_Message::newInstance($subject); $message->setFrom(array($smtpMail => $smtpName)); foreach ($to as $email => $name) { $message->setTo(array($email => $name)); $message->setBody(createEmailText($html, $name, true), 'text/html'); $message->addPart(createEmailText($text, $name, false), 'text/plain'); $unsubscribeLink = $request->getUriForPath('/options/' . $token); $message->getHeaders()->addTextHeader('List-Unsubscribe', '<' . $unsubscribeLink . '>'); $message->getHeaders()->addTextHeader('Precedence', 'bulk'); $successful += $app['mailer']->send($message); } return $successful; }
if ($admin == 'newsletter') { $newsletter = true; } elseif ($admin != 'notifications') { $app->abort(403, "Zugriff verweigert"); } return $app['twig']->render('admin.twig', array('newsletter' => $newsletter)); }); /* Preview: Vorschau der E-Mail */ $app->post('/admin/preview', function (Application $app) { $admin = $app['session']->get('admin'); if ($admin != 'newsletter' && $admin != 'notifications') { $app->abort(403, "Zugriff verweigert"); } $content = $app['request']->get('content'); $html = createEmailText($content, 'Huffle', true); $text = createEmailText($content, 'Huffle', false); $app['session']->set('text', $content); return $app['twig']->render('preview.twig', array('text' => array('html' => $html, 'text' => $text))); }); /* Versenden */ $app->get('/admin/send', function (Application $app, Request $request) use($dbTablePrefix) { /* Security Stuff */ $admin = $app['session']->get('admin'); if ($admin != 'newsletter' && $admin != 'notifications') { $app->abort(403, "Zugriff verweigert"); } $subject = "Huffle-News Benachrichtigung"; // Betreff bei $admin == 'notifications' $text = $app['session']->get('text'); if (!trim($text)) { $app->abort(403, "Fehler: Kein Text übergeben");