function sendMails($data, $arrLang, $type, $arrConf, $pDB, $module_name, $idEvent) { $emails = $data['emails_notification']; $start = $data['startdate']; $end = $data['enddate']; $starttime = $data['starttime']; $event_type = $data['eventtype']; $event = $data['subject']; $description = $data['description']; $endtime = $data['endtime']; $IcalTmp = ""; $pCalendar = new paloSantoCalendar($pDB); $user = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : ""; $uid = Obtain_UID_From_User($user, $arrConf); $pDB3 = new paloDB($arrConf['dsn_conn_database1']); $user_name = $pCalendar->getNameUsers($uid, $pDB3); $user_name1 = $pCalendar->getDescUsers($uid, $pDB3); if (!isset($user_name) || $user_name == "") { $user_name = $user; } if ($uid == "" || !isset($uid)) { return; } // validar el error de envio de email //obtain email FROM.... $From = '*****@*****.**'; $subject = $arrLang['New_Event'] . ": " . $event; if ($type == "NEW") { $subject = $arrLang['New_Event'] . ": " . $event; } if ($type == "UPDATE") { $subject = $arrLang['Change_Event'] . ": " . $event; } if ($type == "DELETE") { $subject = $arrLang['Delete_Event'] . ": " . $event; } $event_type = returnTypeEvent($event_type, $arrLang); $val = false; if ($type != "DELETE") { //$dirIcalTmp = "/tmp/icalout.ics"; $IcalTmp = createTmpIcal($arrLang, $pDB, $module_name, $arrConf, $idEvent); // write the file /tmp/icalout.ics /*$file = fopen($dirIcalTmp, "r"); $encoded_attach = ""; if($file){ $contenido = fread($file, filesize($dirIcalTmp)); $encoded_attach = chunk_split(base64_encode($contenido)); $val = true; }*/ } $startarray = explode(" ", $starttime); $endarray = explode(" ", $endtime); $emails = str_replace('"', "", $emails); $arrEmails = explode(",", $emails); $msg = "\n<html>\n <head>\n <title>{$subject}</title>\n </head>\n <body>\n <h1 style='background-color:#A9A9A9; border-bottom:solid 1px #3b6d92; padding:10px 40px; font-size:28px; color:#fcfdff;'> {$arrLang['notification_event']}</h1>\n <div style='margin:0px 40px;'>\n <div style='color:#000; font-size:26px; padding:15px 0px; margin-bottom:20px;'>\n {$subject}\n </div>\n <div style='margin-top:20px;'>\n <span style='font-style:italic; font-weight:bolder; font-size: 16px;'>{$arrLang['Dear User']}: </span>\n </div>\n <div style='margin-top:20px; margin-bottom:30px;'>\n {$arrLang['invitation_event']}:\n </div>\n <div style='margin-top:10px; margin-left:40px;'>\n <div style='margin-top:10px; font-style:italic; font-weight:bolder;'>{$arrLang['Event']}: </div>\n <div style='margin:0px 0px 0px 60px'>{$event}.</div>\n </div>\n <div style='margin-top:10px; margin-left:40px;'>\n <div style='margin-top:10px; font-style:italic; font-weight:bolder;'>{$arrLang['Date']}: </div>\n <div style='margin:0px 0px 0px 60px'>" . date("d M Y", strtotime($start)) . " - " . date("d M Y", strtotime($end)) . ".</div>\n </div>\n <div style='margin-top:10px; margin-left:40px;'>\n <div style='margin-top:10px; font-style:italic; font-weight:bolder;'>{$arrLang['time']}: </div>\n <div style='margin:0px 0px 0px 60px'>" . $startarray[1] . " - " . $endarray[1] . ".</div>\n </div>"; if ($description != "") { $msg .= "<div style='margin-top:10px; margin-left:40px;'>\n <div style='margin-top:10px; font-style:italic; font-weight:bolder;'>{$arrLang['Description']}: </div>\n <div style='margin:0px 0px 0px 60px'>{$description}.</div>\n </div>"; } $msg .= "<div style='margin-top:10px; margin-left:40px;'>\n <div style='margin-top:10px; font-style:italic; font-weight:bolder;'>{$arrLang['Organizer']}: </div>\n <div style='margin:0px 0px 0px 60px'>" . $user_name1 . " - " . $user_name . ".</div>\n </div>\n <div style='margin-top:20px; text-align: center; color: #BEBEBE; font-size: 12px;'>\n <b>{$arrLang['noResponseNotification']}.</b><br />\n <b>{$arrLang['copyrightNotification']}. 2006 - " . date("Y") . "</b><br />\n </div>\n </div>\n </body>\n </html>"; //Agregamos al cuerpo del mensaje la iCal // $msg .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n'; // $msg .= "Content-Transfer-Encoding: 8bit\n\n"; // $msg .= file_get_contents($dirIcalTmp,true); $msg = utf8_decode($msg); $mail = new PHPMailer(); $mail->Host = "localhost"; $mail->Body = $msg; $mail->IsHTML(true); // El correo se envía como HTML $mail->WordWrap = 50; $mail->From = $From; $mail->FromName = $user_name1 . " (" . $user_name . ")"; /*if($val){ $mail->AddAttachment($dirIcalTmp, "icalout.ics"); }*/ if ($IcalTmp != "") { $mail->AddStringAttachment($IcalTmp, "icalout.ics", "7bit", "text/calendar; charset=utf-8; method=REQUEST"); } for ($i = 0; $i < count($arrEmails) - 1; $i++) { $To = $arrEmails[$i]; $cabecerasIcal = ""; $cuerpo = ""; $posini = strpos($To, "<"); $posend = strpos($To, ">"); if ($posini || $posend) { $ToSend = substr($To, $posini + 1, -1); } else { $ToSend = $To; } $mail->ClearAddresses(); $mail->Subject = utf8_decode($subject); $mail->AddAddress($ToSend, $To); $mail->Send(); } if ($val) { fclose($file); unlink($dirIcalTmp); } }