I'm trying to send an email Outlook calendar invitation with Laravel 5, the mail driver is Mandrill. So, I found this code that actualy works sending the email via php mail() function.
But when I try to pass this to Laravel, Outlook does not recognize the email as a calendar invitation and does not show the calendar accept/decline buttons.
The php code is as follows:
/**
* sends an iCal event mail
* @param Timestamp $tsStart - timestart of the start time
* @param Timestamp $tsEnd - timestamp of end date
* @param String $location - location of event
* @param String $summary - event summary
* @param String $to - list of email recipients
* @param String $subject - email subject
*/
private function sendCalEntry( $tsStart, $tsEnd, $location, $summary, $title, $resources, $to, $subject ){
$from = ORGANISATIONREPLYMAIL;
$dtstart = date('Ymd',$tsStart).'T'.date('His',$tsStart);
$dtend = date('Ymd',$tsEnd).'T'.date('His',$tsEnd);
$loc = $location;
$vcal = "BEGIN:VCALENDAR\r\n";
$vcal .= "VERSION:2.0\r\n";
$vcal .= "PRODID:-//nonstatics.com//OrgCalendarWebTool//EN\r\n";
$vcal .= "METHOD:REQUEST\r\n";
$vcal .= "BEGIN:VEVENT\r\n";
$vcal .= "ORGANIZER;CN=\"".ORGANISATIONNAME." (".$_SESSION['username'].")"."\":mailto:".ORGANISATIONREPLYMAIL."\r\n";
$vcal .= "UID:".date('Ymd').'T'.date('His')."-".rand()."-nonstatics.com\r\n";
$vcal .= "DTSTAMP:".date('Ymd').'T'.date('His')."\r\n";
$vcal .= "DTSTART:$dtstart\r\n";
$vcal .= "DTEND:$dtend\r\n";
$vcal .= "LOCATION:$location\r\n";
$vcal .= "SUMMARY:$summary\r\n";
$vcal .= "DESCRIPTION:Hinweis/Fahrer:$summary - Folgende Resourcen wurden gebucht: $resources \r\n";
$vcal .= "BEGIN:VALARM\r\n";
$vcal .= "TRIGGER:-PT15M\r\n";
$vcal .= "ACTION:DISPLAY\r\n";
$vcal .= "DESCRIPTION:Reminder\r\n";
$vcal .= "END:VALARM\r\n";
$vcal .= "END:VEVENT\r\n";
$vcal .= "END:VCALENDAR\r\n";
$headers = "From: $from\r\nReply-To: $from";
$headers .= "\r\nMIME-version: 1.0\r\nContent-Type: text/calendar; name=calendar.ics; method=REQUEST; charset=\"iso-8859-1\"";
$headers .= "\r\nContent-Transfer-Encoding: 7bit\r\nX-Mailer: Microsoft Office Outlook 12.0";
return @mail($to, $subject . " " . $summary . " / " . $resources, $vcal, $headers);
}
My code in Laravel is as follows:
//Data send by the user
$data['start_date']='20150128';
$data['texto']='Texto Texto Texto Texto ';
$data['titulo']='Recordatorio';
$data['destinatario']='nata_r10@hotmail.com';
Mail::send('emails.seguimiento', ['mensaje' => 'Testmail'], function($message) use($data)
{
//Parameter defined for the vCalendar
$filename = "invite.ics";
$meeting_duration = (3600 * 2); // 2 hours
$meetingstamp = strtotime( $data['start_date'] . " UTC");
$dtstart = gmdate('Ymd\THis\Z', $meetingstamp);
$dtend = gmdate('Ymd\THis\Z', $meetingstamp + $meeting_duration);
$todaystamp = gmdate('Ymd\THis\Z');
$uid = date('Ymd').'T'.date('His').'-'.rand().'@yourdomain.com';
$description = strip_tags($data['texto']);
$location = "Telefone ou vídeo conferência";
$titulo_invite = "Your meeting title";
$organizer = "CN=Organizer name:email@YourOrganizer.com";
//Including additional headers
$typemime = $message->getHeaders()->get("MIME-version");
$typemime->setValue("1.0");
$type = $message->getHeaders()->get("Content-Type");
$type->setValue("text/calendar");
$type->setParameters(array(
"name" => "calendar.ics",
"method" => "REQUEST",
"charset" => "iso-8859-1"
));
$typetrans = $message->getHeaders()->get("Content-Transfer-Encoding");
$typetrans->setValue("7bit");
$message->getHeaders()->addTextHeader("X-Mailer", "Microsoft Office Outlook 12.0");
//Defining subject and destination
$message->subject($data['titulo']);
$message->to($data['destinatario']);
//vCalendar parameters
$vcal = "BEGIN:VCALENDAR\r\n";
$vcal .= "VERSION:2.0\r\n";
$vcal .= "PRODID:-//nonstatics.com//OrgCalendarWebTool//EN\r\n";
$vcal .= "METHOD:REQUEST\r\n";
$vcal .= "BEGIN:VEVENT\r\n";
$vcal .= "ORGANIZER;CN=\"Solinfra (Nataly Rocha)"."\":mailto:nata_r10@hotmail.com\r\n";
$vcal .= "UID:".date('Ymd').'T'.date('His')."-".rand()."-nonstatics.com\r\n";
$vcal .= "DTSTAMP:".date('Ymd').'T'.date('His')."\r\n";
$vcal .= "DTSTART:$dtstart\r\n";
$vcal .= "DTEND:$dtend\r\n";
$vcal .= "LOCATION:$location\r\n";
$vcal .= "SUMMARY:resuuuuumen\r\n";
$vcal .= "DESCRIPTION:Hinweis/Fahrer:resuuuuumen - Folgende Resourcen wurden gebucht: resources \r\n";
$vcal .= "BEGIN:VALARM\r\n";
$vcal .= "TRIGGER:-PT15M\r\n";
$vcal .= "ACTION:DISPLAY\r\n";
$vcal .= "DESCRIPTION:Reminder\r\n";
$vcal .= "END:VALARM\r\n";
$vcal .= "END:VEVENT\r\n";
$vcal .= "END:VCALENDAR\r\n";
//Adding the parameters (This part Im not sure hoy to do it)
$message->addPart($vcal, 'text/calendar; method=REQUEST', 'iso-8859-1');
});
Seems like the part off adding the $vcal values to the email is the one missing because I checked the headers and those are being added. Thanks for your help.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire