Jump to content

mailing


SVerheijen

Recommended Posts

This code sends multiple mails with in each one a agenda file. I want it to send 1 mail for all of them. Does anyone know how to change this code to do that or should i just recreate it with a code from scratch?

<?php
if (session_id() === "") {
session_start();
}
setlocale(LC_ALL, "nl_NL.UTF-8");
include '../../includes/authorize.php';
include '../resources/database/MysqliDb.php';
$db = new MysqliDb ($server, $user, $password, $database);

include '../../includes/authorize.php';
if (!empty($_POST)) {
sendMails($_POST['changes']);
}

/**
* @param $data array of users with the changes made that affect them
*
* @return array
*/
function sendMails($data)
{
if (isset($_GET['showAs'])) {
$showAs = $_GET['showAs'];
} else {
$showAs = "BUSY";
}
try {


foreach ($data as $user) {
$to = $user['info']['naam'] . " <" . $user['info']['email'] . ">";

if ($user['info']['email'] == $_POST['organizer']['email']) {
$organizer = "Wijzigingsbeheer";
$organizer_email = "wijzigingsbeheer@summacollege.nl";
} else {
$organizer = $_POST['organizer']['naam'];
$organizer_email = $_POST['organizer']['email'];
}-

$participant_name = $user['info']['naam'];
$participant_email = $user['info']['email'];


foreach ($user['changes'] as $change) {
$date = date("Ymd", strtotime($change['date']));
//OLD
/* if ($change['daypart'] == 0) {
$startTime = '0830';
$endTime = '1230';
} else {
$startTime = '1300';
$endTime = '1700';
} */
//NEW
switch ($change['daypart']) {
case 0:
$startTime = '0830';
$endTime = '1230';
break;
case 1:
$startTime = '1300';
$endTime = '1700';
break;
case 2:
$startTime = '1730';
$endTime = '2230';
break;
default:
$startTime = '0830';
$endTime = '1230';
}

$subject = $_POST['newTask']['name'];
$desc = 'Veranderingen in het planbord';

$headers = "Content-type: text/calendar; Content-Disposition: inline; charset=utf-8; filename=calendar.ics;";
// $headers .= "Content-Type: text/plain;charset=\"utf-8\"";

$UniqueID = time() + rand(0, 100);

$message =
"BEGIN:VCALENDAR\r\n"
. "PRODID:-//Planbord\r\n"
. "VERSION:2.0\r\n"
. "METHOD:REQUEST\r\n"
. "BEGIN:VEVENT\r\n"
. "DTSTAMP:" . date('Ymd') . 'T' . date('His') . "\r\n"
. "DTSTART:" . $date . "T" . $startTime . "00\r\n"
. "ORGANIZER;CN=" . $organizer . ":mailto:" . $organizer_email . "\r\n"
. "SUMMARY:" . $subject . "\r\n"
. "UID: " . $UniqueID . "\r\n"
. "DTEND:" . $date . "T" . $endTime . "00\r\n"
. "LOCATION: Uw werkplek \r\n"
. "DESCRIPTION:" . $desc . "\r\n"
. "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;CN=" . $participant_name . " :MAILTO:" . $participant_email . "\r\n"
. "X-MICROSOFT-CDO-BUSYSTATUS:" . $showAs . "\r\n"
. "END:VEVENT\r\n"
. "END:VCALENDAR";


$headers .= $message;


mail($to, $subject, $message, $headers);
}


}
} catch (Exception $ex) {
$return['code'] = 500;
$return['message'] = "Er is iets mis gegaan met het versturen van de mails, deze foutmelding kan helpen met het oplossen: " . $ex;
return;
}
$return['code'] = 200;
$return['message'] = "De mails zijn verzonden.";
return;
}
Edited by SVerheijen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.