Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once($CFG->dirroot.'/lib/phpmailer/moodle_phpmailer.php');
- $mail = new PHPMailer();
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = $CFG->smtphosts; // Specify main and backup server
- $mail->Port = 587;
- $mail->SMTPAuth = true;
- $mail->Username = $CFG->smtpuser; // SMTP username
- $mail->Password = $CFG->smtppass;
- $mail->SetFrom($CFG->smtpuser); // Enable SMTP authentication
- $mail->addAddress($user->email); // Add a recipient
- $mail->isHTML(true);
- $mail->setLanguage('pl', $CFG->dirroot.'/lib/phpmailer/language/phpmailer.lang-pl.php');
- $mail->CharSet = 'UTF-8';
- $startdate = strftime('%Y%m%d', $enrol->timestart - 60*60);
- $startTime = strftime('%H%M', $enrol->timestart - 60*60);
- $enddate = strftime('%Y%m%d', $enrol->timeend - 60*60);
- $endTime = strftime('%H%M', $enrol->timeend - 60*60);
- $a = new stdClass();
- $a->user = fullname($user);
- $a->fullname = $course->fullname;
- $a->startdate = strftime('%d.%m.%Y %H:%M', $enrol->timestart - 60*60);
- $a->enddate = strftime('%d.%m.%Y %H:%M', $enrol->timeend - 60*60);
- $subject = get_string('email_header', 'local_enrolmail', $a);
- $body = get_string('email_body', 'local_enrolmail', $a);
- $mail->addCustomHeader('Content-Type:text/calendar');
- $mail->addCustomHeader('Content-Disposition: inline');
- $mail->addCustomHeader('charset=utf-8');
- // outlook calendar attachment
- $text = "BEGIN:VCALENDAR\r\n
- VERSION:2.0\r\n
- PRODID:-//Deathstar-mailer//theforce/NONSGML v1.0//EN\r\n
- METHOD:REQUEST\r\n
- BEGIN:VEVENT\r\n
- UID:" . md5(uniqid(mt_rand(), true)) . "example.com\r\n
- DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z\r\n
- DTSTART:".$startdate."T".$startTime."00Z\r\n
- DTEND:".$enddate."T".$endTime."00Z\r\n
- SUMMARY:".$subject."\r\n
- ORGANIZER;CN=".$CFG->fullname.":mailto:".$CFG->smtpuser."\r\n
- LOCATION:".$CFG->wwwroot."\r\n
- DESCRIPTION:".$body."\r\n
- ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN".fullname($user).";X-NUM-GUESTS=0:MAILTO:".$user->email."\r\n
- END:VEVENT\r\n
- END:VCALENDAR\r\n";
- $mail->isHTML(true);
- $mail->Subject = $subject;
- $mail->Body = $body;
- $mail->AltBody = $text; // in your case once more the $text string
- $mail->Ical = $text; // ical format, in your case $text string
- if ($mail->Send()) {
- $mail->ClearAllRecipients();
- $mail->ClearReplyTos();
- $mail->ClearCustomHeaders();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement