Advertisement
Guest User

Untitled

a guest
Jan 4th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. require_once($CFG->dirroot.'/lib/phpmailer/moodle_phpmailer.php');
  2.  
  3. $mail = new PHPMailer();
  4. $mail->isSMTP(); // Set mailer to use SMTP
  5. $mail->Host = $CFG->smtphosts; // Specify main and backup server
  6. $mail->Port = 587;
  7. $mail->SMTPAuth = true;
  8. $mail->Username = $CFG->smtpuser; // SMTP username
  9. $mail->Password = $CFG->smtppass;
  10. $mail->SetFrom($CFG->smtpuser); // Enable SMTP authentication
  11. $mail->addAddress($user->email); // Add a recipient
  12. $mail->isHTML(true);
  13. $mail->setLanguage('pl', $CFG->dirroot.'/lib/phpmailer/language/phpmailer.lang-pl.php');
  14. $mail->CharSet = 'UTF-8';
  15.  
  16. $startdate = strftime('%Y%m%d', $enrol->timestart - 60*60);
  17. $startTime = strftime('%H%M', $enrol->timestart - 60*60);
  18. $enddate = strftime('%Y%m%d', $enrol->timeend - 60*60);
  19. $endTime = strftime('%H%M', $enrol->timeend - 60*60);
  20.  
  21. $a = new stdClass();
  22. $a->user = fullname($user);
  23. $a->fullname = $course->fullname;
  24. $a->startdate = strftime('%d.%m.%Y %H:%M', $enrol->timestart - 60*60);
  25. $a->enddate = strftime('%d.%m.%Y %H:%M', $enrol->timeend - 60*60);
  26.  
  27. $subject = get_string('email_header', 'local_enrolmail', $a);
  28. $body = get_string('email_body', 'local_enrolmail', $a);
  29.  
  30. $mail->addCustomHeader('Content-Type:text/calendar');
  31. $mail->addCustomHeader('Content-Disposition: inline');
  32. $mail->addCustomHeader('charset=utf-8');
  33.  
  34. // outlook calendar attachment
  35. $text = "BEGIN:VCALENDAR\r\n
  36. VERSION:2.0\r\n
  37. PRODID:-//Deathstar-mailer//theforce/NONSGML v1.0//EN\r\n
  38. METHOD:REQUEST\r\n
  39. BEGIN:VEVENT\r\n
  40. UID:" . md5(uniqid(mt_rand(), true)) . "example.com\r\n
  41. DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z\r\n
  42. DTSTART:".$startdate."T".$startTime."00Z\r\n
  43. DTEND:".$enddate."T".$endTime."00Z\r\n
  44. SUMMARY:".$subject."\r\n
  45. ORGANIZER;CN=".$CFG->fullname.":mailto:".$CFG->smtpuser."\r\n
  46. LOCATION:".$CFG->wwwroot."\r\n
  47. DESCRIPTION:".$body."\r\n
  48. ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN".fullname($user).";X-NUM-GUESTS=0:MAILTO:".$user->email."\r\n
  49. END:VEVENT\r\n
  50. END:VCALENDAR\r\n";
  51. $mail->isHTML(true);
  52. $mail->Subject = $subject;
  53. $mail->Body = $body;
  54.  
  55. $mail->AltBody = $text; // in your case once more the $text string
  56. $mail->Ical = $text; // ical format, in your case $text string
  57.  
  58. if ($mail->Send()) {
  59. $mail->ClearAllRecipients();
  60. $mail->ClearReplyTos();
  61. $mail->ClearCustomHeaders();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement