inbox = imap_open("{" . MAIL_SERVER . ":" . MAIL_SERVER_PORT . MAIL_SERVER_FLAGS . "}INBOX", MAIL_USER, MAIL_PASSWORD) or die("can't connect:" . imap_last_error()); } public function __destruct() { imap_close($this->inbox); } public function getNewMessages() { return imap_search($this->inbox, 'UNSEEN'); } public function fetchMessageStructure($email) { return imap_fetchstructure($this->inbox, $email); } public function fetchMessageBody($email, $section) { return imap_fetchbody($this->inbox, $email, $section); } public function headerInfo($email) { $headerInfo = imap_headerinfo($this->inbox, $email); $additionalHeaderInfo = imap_fetchheader($this->inbox, $email); $infos = explode("\n", $additionalHeaderInfo); foreach($infos as $info) { $data = explode(":", $info, 2); if( count($data) == 2 && !isset($head[$data[0]])) { if(trim($data[0]) === 'X-Original-To') { $headerInfo->{'X-Original-To'} = trim($data[1]); // break; } else if(trim($data[0]) === 'Message-ID') { $headerInfo->{'Message-ID'} = trim($data[1]); } else if(trim($data[0]) === 'In-Reply-To') { $headerInfo->{'In-Reply-To'} = trim($data[1]); } } } return $headerInfo; } public function reply($sender, $sendername, $response = null) { $server = NC_SERVER; if(strstr($server, "https://")) { $server = str_replace('https://', '', $server); } else if(strstr($server, "http://")) { $server = str_replace('http://', '', $server); } $mail = new PHPMailer(true); try { $mail->isSMTP(); $mail->Host = MAIL_SERVER; $mail->SMTPAuth = true; $mail->Username = MAIL_USER; $mail->Password = MAIL_PASSWORD; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = MAIL_SERVER_SMTPPORT; $mail->setFrom(MAIL_USER, 'Mail2Deck Notification'); $mail->isHTML(true); $mail->SMTPOptions = [ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ], ]; if($response) { $body = "

We received your request and opened a support ticket. You can see it here: board}/card/{$response->id}" . "\">Newroco Support.

" ."

To access the card, you will be asked to login, please use your company usual account details.

" ."

Please add more details or respond to any comments from our team, so we can address the issue as fast as possible.



" ."

Thank you for reaching out.


" ."Newroco" ."|" ."Support Team
" ."" ."newroco" ."

"; $subject = 'We received your support request'; } else { $body = "

There was a problem creating a new card.

Make sure the board was setup correctly.

"; $subject = "A new card could not be created!"; } //Inline image $description = $response->description; $pattern = '/\[(.*?)\]\((.*?)\)/'; if (preg_match($pattern, $description)) { $descriptionFormatted = preg_replace('/\[(.*?)\]\((.*?)\)/', '$1', $description); } $bodySupport="

board}/card/{$response->id}" . "\">{$response->title}

" ."

{$descriptionFormatted}

" ."

Sent by: {$sender}

"; /** * EMAIL 1: email to sender */ $mail->addAddress($sender); $mail->Subject = $subject; $mail->Body = "" ."mail2deck response" ."$body" .""; $mail->send(); echo "Mail sent successfully to $sender."; if(MAIL_SUPPORT != ''){ // Clean recipients and attachments for the next email $mail->clearAddresses(); $mail->clearAttachments(); /** * EMAIL 2: email to support team */ $mail->addAddress(MAIL_SUPPORT); $mail->addReplyTo($sender, $sendername); $mail->Subject = "New Card Issue Notification"; $mail->Body = "" ."mail2deck response" ."$bodySupport" .""; $mail->send(); echo "Mail sent successfully to support team."; } } catch (Exception $e) { echo "Mail could not be sent. PHPMailer Error: {$mail->ErrorInfo}"; } } /** * Mark emails for deletion * * @param $email email number that you want to delete * * @return void */ public function delete(int $email) { imap_delete($this->inbox, imap_uid($this->inbox, $email), FT_UID); } /** * Delete all messages marked for deletion */ public function expunge() { imap_expunge($this->inbox); } }