1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'PHPMailer/vendor/autoload.php';
$event_id = 1234;
$sequence = 0;
$status = 'TENTATIVE';
//event params
$summuary = $_POST['summuary'];
$venue = $_POST['lieu'];
$start = $_POST['date_debut'];
$start_time = $_POST['heur_debut'];
$end = $_POST['date_fin'];
$end_time = $_POST['heur_fin'];
$description = $_POST['description'];
$destinataire = $_POST['emailEvent'];
$mail = new PHPMailer(true);
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'ssl0.ovh.net'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '*******'; // SMTP username
$mail->Password = '******'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('*********', 'test event');
$mail->addAddress($destinataire, 'Toi'); // Add a recipient
$mail->ContentType = 'text/calendar';
//Content
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Outlook event';
$mail->addCustomHeader('MIME-version',"1.0");
$mail->addCustomHeader('Content-type',"text/calendar; method=REQUEST; charset=UTF-8");
$mail->addCustomHeader('Content-Transfer-Encoding',"7bit");
$mail->addCustomHeader('X-Mailer',"Microsoft Office Outlook 12.0");
$mail->addCustomHeader("Content-class: urn:content-classes:calendar");
$ical = "BEGIN:VCALENDAR\r\n";
$ical .= "VERSION:2.0\r\n";
$ical .= "PRODID:-//YourCassavaLtd//EateriesDept//EN\r\n";
$ical .= "METHOD:REQUEST\r\n";
$ical .= "BEGIN:VEVENT\r\n";
$ical .= "ORGANIZER;SENT-BY=\"MAILTO:organizer@kaserver.com\":MAILTO:onbehalfoforganizer@kaserver.com\r\n";
$ical .= "ATTENDEE;CN=them@kaserver.com;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE:mailto:organizer@kaserver.com\r\n";
$ical .= "UID:".strtoupper(md5($event_id))."-kaserver.com\r\n";
$ical .= "SEQUENCE:".$sequence."\r\n";
$ical .= "STATUS:".$status."\r\n";
$ical .= "DTSTAMPTZID=Africa/Nairobi:".date('Ymd').'T'.date('His')."\r\n";
$ical .= "DTSTART:".$start."T".$start_time."\r\n";
$ical .= "DTEND:".$end."T".$end_time."\r\n";
$ical .= "LOCATION:".$venue."\r\n";
$ical .= "SUMMARY:".$summuary."\r\n";
$ical .= "DESCRIPTION:" str_replace("\r\n", "\\n", $description);
$ical .= "BEGIN:VALARM\r\n";
$ical .= "TRIGGER:-PT15M\r\n";
$ical .= "ACTION:DISPLAY\r\n";
$ical .= "DESCRIPTION:Reminder\r\n";
$ical .= "END:VALARM\r\n";
$ical .= "END:VEVENT\r\n";
$ical .= "END:VCALENDAR\r\n";
$mail->Body = $ical;
//send the message, check for errors
if(!$mail->send()) {
$this->error = "Mailer Error: " . $mail->ErrorInfo;
return false;
} else {
$this->error = "Message sent!";
return true; |
Partager