Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

icalendar and phpmailer.php

i am trying to send icalendar to the users, so that they can open these ics files in outlook and save the appointment. mailer i am using is 'phpmailer.php'.

problem is that it sends ical format as html in message body. Here is my code


$text="
BEGIN:VCALENDAR
VERSION:1.0
BEGIN:VEVENT
CATEGORIES:MEETING
STATUS:TENTATIVE
DTSTART:".$startDateTime."
DTEND:".$endDateTime."
SUMMARY:Interview for the candidate".$cname."
DESCRIPTION:".$message."
CLASS:PRIVATE
END:VEVENT
END:VCALENDAR";

$mail->SetFrom('[email protected]', 'xxxx');
$mail->IsSMTP();
$mail->Host = "smtp.mail.yahoo.com";

$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'xxxxx';


$mail->AddAddress($addresses[$i]);
$mail->Subject    = "Interview schedule of Candidate";

    $headers = "From: Sender\n";
        $headers .= "Reply-To: [email protected]\n";
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-Type: text/calendar; method=REQUEST; charset=utf-8\n";
        $headers .= "Content-Transfer-Encoding: 8bit\n";
        $headers .= "Content-class: urn:content-classes:calendarmessage\n";
$mail->Body=$body;

if(!$mail->Send($headers,$body)) 
{
        echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message sent!";
}


Please let me know what is wrong with my code. Thanks in advance

like image 914
Saghir A. Khatri Avatar asked Aug 03 '26 06:08

Saghir A. Khatri


1 Answers

The following solution worked for me:

$mail->Subject = $name;
$mail->Body = $description; 
$mail->AltBody = $body; // in your case once more the $text string
$mail->Ical = $message; // ical format, in your case $text string
like image 122
croppio.com Avatar answered Aug 05 '26 21:08

croppio.com



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!