• Resolved A31

    (@a31)


    Good Evening,

    I hope that someone can help me.

    What I would like to achieve is to send an ics or Outlook Meeting invite through an email.

    So here is some of my code (i only copy relevant parts because i use a class that manages mailer, the same class sends normal email perfectly):

    $date = "20170515";
    $startTime = "1300";
    $endTime = "1400";
    $subject = "Meeting";
    $desc = "Details";
    
        $SendMail_To = '[email protected]';
        $SendMail_Subject = 'TESTING';
        $SendMail_Message = "
                BEGIN:VCALENDAR
                VERSION:2.0
                PRODID:-//hacksw/handcal//NONSGML v1.0//EN
                BEGIN:VEVENT
                UID:" . md5(uniqid(mt_rand(), true)) . "example.com
                DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
                DTSTART:".$date."T".$startTime."00Z
                DTEND:".$date."T".$endTime."00Z
                SUMMARY:".$subject."
                DESCRIPTION:".$desc."
                END:VEVENT
                END:VCALENDAR
                ";

    Then in my mailer class I change the following:

    function set_html_content_type()
    {
       //return 'text/html';
       return 'text/calendar';
    }
                        
    add_filter ('wp_mail_content_type', 'set_html_content_type' );
                        
                        wp_mail($SendMail_To,$SendMail_Subject,$SendMail_Message,$Headers,$Attachment_Array);
                                            
    remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

    I receive the email fine, and there is a Calendar Item attached, but when I want to open the attachment, it tells me that it cannot open the file.

    Can you please help?

Viewing 1 replies (of 1 total)
  • Thread Starter A31

    (@a31)

    As luck would have it… many hours before the query… but right after I post for help , I get a solution. Here is my code now:

    $sequence = 0;
    $event_id = 1234;
    $status = 'TENTATIVE';
    
    $start = '20170510';
    $start_time = '160630';
    $end = '20170510';
    $end_time = '180630';
    $subject = "Meeting";
    $desc = "Details";
    
    $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:[email protected]\":MAILTO:[email protected]\r\n";
    $ical .= "ATTENDEE;[email protected];ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE:mailto:[email protected]\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:".$summary."\r\n";
    $ical .= "DESCRIPTION:".$event['description']."\r\n";
    $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";
    
        $SendMail_To = '[email protected]';
        $SendMail_Subject = 'TESTING';
        $SendMail_Message = $ical;
    function set_html_content_type()
                        {
                            //return 'text/html';
                            return 'text/calendar';
                        }
                        
                        add_filter ('wp_mail_content_type', 'set_html_content_type' );
                        
                        wp_mail($SendMail_To,$SendMail_Subject,$SendMail_Message,$Headers,$Attachment_Array);
                                            
                        remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

    Hope this can help someone else…

Viewing 1 replies (of 1 total)
  • The topic ‘WP_Mail ICS Outlook Meeting Invite’ is closed to new replies.