function _sendSummaryEmail()
 {
     if (count($this->_getMsgIDs()) < 1) {
         $this->_addToSummary('No ARB emails to process');
         return;
     }
     $summary = $this->_summaryToString();
     $envelope["from"] = ini_get('sendmail_from');
     $body[] = array("type" => TYPEMULTIPART, "subtype" => "mixed");
     $body[] = array('type' => 0, 'encoding' => 0, 'subtype' => "PLAIN", 'contents.data' => $summary);
     foreach ($this->_getAttachments() as $filename => $attachment) {
         $body[] = array('type' => 0, 'encoding' => 0, 'subtype' => "X-COMMA-SEPARATED-VALUES", 'description' => $filename, 'disposition.type' => 'attachment', 'disposition' => array('filename' => $filename), 'dparameters.filename' => $filename, 'parameters.name' => $filename, 'contents.data' => $attachment);
     }
     $msg = imap_mail_compose($envelope, $body);
     list($t_header, $t_body) = split("\r\n\r\n", $msg, 2);
     $t_header = str_replace("\r", '', $t_header);
     $success = imap_mail(_CRM_PROCESS_AUTHORIZE_REPORT_SUMMARY_TO_EMAIL, 'Authorize.net Report Processesing Summary', $t_body, $t_header);
 }
Exemple #2
1
 function SendMail($rfc822, $smartdata = array(), $protocolversion = false)
 {
     // file_put_contents(BASE_PATH."/mail.dmp/".$this->_folderid(), $rfc822);
     if ($protocolversion < 14.0) {
         debugLog("IMAP-SendMail: " . (isset($rfc822) ? $rfc822 : "") . "task: " . (isset($smartdata['task']) ? $smartdata['task'] : "") . " itemid: " . (isset($smartdata['itemid']) ? $smartdata['itemid'] : "") . " parent: " . (isset($smartdata['folderid']) ? $smartdata['folderid'] : ""));
     }
     $mimeParams = array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\r\n", 'charset' => 'utf-8');
     $mobj = new Mail_mimeDecode($mimeParams['input'], $mimeParams['crlf']);
     $message = $mobj->decode($mimeParams, $mimeParams['crlf']);
     $Mail_RFC822 = new Mail_RFC822();
     $toaddr = $ccaddr = $bccaddr = "";
     if (isset($message->headers["to"])) {
         $toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["to"]));
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["cc"]));
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["bcc"]));
     }
     $map_user_fullname = false;
     if (defined('IMAP_USERNAME_FULLNAME') && strlen(IMAP_USERNAME_FULLNAME) > 0) {
         $map_user_fullname = unserialize(IMAP_USERNAME_FULLNAME);
     }
     $addedfullname = false;
     // save some headers when forwarding mails (content type & transfer-encoding)
     $headers = "";
     $forward_h_ct = "";
     $forward_h_cte = "";
     $envelopefrom = "";
     $use_orgbody = false;
     // clean up the transmitted headers
     // remove default headers because we are using imap_mail
     $changedfrom = false;
     $returnPathSet = false;
     $body_base64 = false;
     $org_charset = "";
     $org_boundary = false;
     foreach ($message->headers as $k => $v) {
         if ($k == "subject" || $k == "to" || $k == "cc" || $k == "bcc" || $k == "sender") {
             continue;
         }
         debugLog("Header Sentmail: " . $k . " = " . trim($v));
         if ($k == "content-type") {
             // if the message is a multipart message, then we should use the sent body
             if (preg_match("/multipart/i", $v)) {
                 $use_orgbody = true;
                 $org_boundary = $message->ctype_parameters["boundary"];
             }
             // save the original content-type header for the body part when forwarding
             if ($smartdata['task'] == 'forward' && $smartdata['itemid'] && !$use_orgbody) {
                 $forward_h_ct = $v;
                 continue;
             }
             if ($smartdata['task'] == 'reply' && $smartdata['itemid'] && !$use_orgbody) {
                 $forward_h_ct = $v;
                 continue;
             }
             // set charset always to utf-8
             $org_charset = $v;
             $v = preg_replace("/charset=([A-Za-z0-9-\"']+)/", "charset=\"utf-8\"", $v);
         }
         if ($k == "content-transfer-encoding") {
             // if the content was base64 encoded, encode the body again when sending
             if (trim($v) == "base64") {
                 $body_base64 = true;
             }
             // save the original encoding header for the body part when forwarding
             if ($smartdata['task'] == 'forward' && $smartdata['itemid']) {
                 $forward_h_cte = $v;
                 continue;
             }
         }
         // if the message is a multipart message, then we should use the sent body
         if (($smartdata['task'] == 'new' || $smartdata['task'] == 'reply' || $smartdata['task'] == 'forward') && (isset($smartdata['replacemime']) && $smartdata['replacemime'] == true || $k == "content-type" && preg_match("/multipart/i", $v))) {
             $use_orgbody = true;
             $org_boundary = $message->ctype_parameters["boundary"];
         }
         // check if "from"-header is set, do nothing if it's set
         // else set it to IMAP_DEFAULTFROM
         if ($k == "from") {
             if (trim($v)) {
                 $changedfrom = true;
                 ini_set('sendmail_from', $v);
                 $fromaddr = $v;
             } elseif (!trim($v) && IMAP_DEFAULTFROM) {
                 $changedfrom = true;
                 if (IMAP_DEFAULTFROM == 'username') {
                     $v = $this->_username;
                 } else {
                     if (IMAP_DEFAULTFROM == 'domain') {
                         $v = $this->_domain;
                     } else {
                         $v = $this->_username . IMAP_DEFAULTFROM;
                     }
                 }
                 $envelopefrom = "-f{$v}";
                 ini_set('sendmail_from', $v);
                 $fromaddr = $v;
             }
         }
         // depending on from field and if username is in map_user_fullname, we add users full name here to the email
         // address
         if ($k == "from" && $map_user_fullname && isset($map_user_fullname[$this->_username])) {
             $addedfullname = true;
             $v_parts = explode(" ", str_replace(">", "", str_replace("<", "", $v)));
             $v = '"' . $map_user_fullname[$this->_username] . '" <' . $v_parts[sizeof($v_parts) - 1] . '>';
         }
         // check if "Return-Path"-header is set
         if ($k == "return-path") {
             $returnPathSet = true;
             if (!trim($v) && IMAP_DEFAULTFROM) {
                 if (IMAP_DEFAULTFROM == 'username') {
                     $v = $this->_username;
                 } else {
                     if (IMAP_DEFAULTFROM == 'domain') {
                         $v = $this->_domain;
                     } else {
                         $v = $this->_username . IMAP_DEFAULTFROM;
                     }
                 }
                 $envelopefrom = "-f{$v}";
                 ini_set('sendmail_from', $v);
                 $fromaddr = $v;
             }
         }
         // all other headers stay
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= ucfirst($k) . ": " . trim($v);
     }
     // set "From" header if not set on the device
     if (IMAP_DEFAULTFROM && !$changedfrom) {
         if (IMAP_DEFAULTFROM == 'username') {
             $v = $this->_username;
         } else {
             if (IMAP_DEFAULTFROM == 'domain') {
                 $v = $this->_domain;
             } else {
                 $v = $this->_username . IMAP_DEFAULTFROM;
             }
         }
         $envelopefrom = "-f{$v}";
         ini_set('sendmail_from', $v);
         $fromaddr = $v;
         $v_parts = explode(" ", str_replace(">", "", str_replace("<", "", $v)));
         if ($map_user_fullname && isset($map_user_fullname[$this->_username])) {
             $v = '"' . $map_user_fullname[$this->_username] . '" <' . $v_parts[sizeof($v_parts) - 1] . '>';
         }
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'From: ' . $v;
     }
     // set "Return-Path" header if not set on the device
     if (IMAP_DEFAULTFROM && !$returnPathSet) {
         if (IMAP_DEFAULTFROM == 'username') {
             $v = $this->_username;
         } else {
             if (IMAP_DEFAULTFROM == 'domain') {
                 $v = $this->_domain;
             } else {
                 $v = $this->_username . IMAP_DEFAULTFROM;
             }
         }
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'Return-Path: ' . $v;
     }
     // if this is a multipart message with a boundary, we must use the original body
     if ($use_orgbody) {
         debugLog("IMAP-Sendmail: use_orgbody = true");
         list(, $body) = $mobj->_splitBodyHeader($rfc822);
         $repl_body = $this->getBody($message);
     } else {
         debugLog("IMAP-Sendmail: use_orgbody = false");
         $body = $this->getBody($message);
     }
     if (isset($smartdata['replacemime']) && $smartdata['replacemime'] == true && isset($message->ctype_primary)) {
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= "Content-Type: " . $message->ctype_primary . "/" . $message->ctype_secondary . (isset($message->ctype_parameters['boundary']) ? ";\n\tboundary=" . $message->ctype_parameters['boundary'] : "");
     }
     $body = str_replace("\r", "", $body);
     // reply
     if ($smartdata['task'] == 'reply' && isset($smartdata['itemid']) && isset($smartdata['folderid']) && $smartdata['itemid'] && $smartdata['folderid'] && (!isset($smartdata['replacemime']) || isset($smartdata['replacemime']) && $smartdata['replacemime'] == false)) {
         $this->imap_reopenFolder($smartdata['folderid']);
         // receive entire mail (header + body) to decode body correctly
         if (defined("IMAP_USE_FETCHHEADER") && IMAP_USE_FETCHHEADER === false) {
             $origmail = @imap_fetchbody($this->_mbox, $smartdata['itemid'], "", FT_UID | FT_PEEK);
         } else {
             $origmail = @imap_fetchheader($this->_mbox, $smartdata['itemid'], FT_UID) . @imap_body($this->_mbox, $smartdata['itemid'], FT_PEEK | FT_UID);
         }
         $mobj2 = new Mail_mimeDecode($origmail);
         // receive only body
         $body .= $this->getBody($mobj2->decode(array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $origmail, 'crlf' => "\n", 'charset' => 'utf-8')));
         // unset mimedecoder & origmail - free memory
         unset($mobj2);
         unset($origmail);
     }
     // encode the body to base64 if it was sent originally in base64 by the pda
     // the encoded body is included in the forward
     if ($body_base64 && !$use_orgbody && !isset($forward)) {
         debugLog("IMAP-Sendmail: body_base64 = true and use_orgbody = false");
         $body = chunk_split(base64_encode($body));
     } else {
         debugLog("IMAP-Sendmail: body_base64 = false or use_orgbody = false");
     }
     // forward
     if ($smartdata['task'] == 'forward' && isset($smartdata['itemid']) && isset($smartdata['folderid']) && $smartdata['itemid'] && $smartdata['folderid'] && (!isset($smartdata['replacemime']) || isset($smartdata['replacemime']) && $smartdata['replacemime'] == false)) {
         debugLog("IMAP Smartfordward is called");
         $this->imap_reopenFolder($smartdata['folderid']);
         // receive entire mail (header + body)
         if (defined("IMAP_USE_FETCHHEADER") && IMAP_USE_FETCHHEADER === false) {
             $origmail = @imap_fetchbody($this->_mbox, $smartdata['itemid'], "", FT_UID | FT_PEEK);
         } else {
             $origmail = @imap_fetchheader($this->_mbox, $smartdata['itemid'], FT_UID) . @imap_body($this->_mbox, $smartdata['itemid'], FT_PEEK | FT_UID);
         }
         // build a new mime message, forward entire old mail as file
         if (!defined('IMAP_INLINE_FORWARD') || IMAP_INLINE_FORWARD === false) {
             if ($body_base64) {
                 $body = chunk_split(base64_encode($body));
             }
             $boundary = $org_boundary ? $org_boundary : false;
             // build a new mime message, forward entire old mail as file
             list($aheader, $body) = $this->mail_attach("forwarded_message.eml", strlen($origmail), $origmail, $body, $forward_h_ct, $forward_h_cte, $boundary);
             $headers .= "\n{$aheader}";
         } else {
             $mobj2 = new Mail_mimeDecode($origmail);
             $mess2 = $mobj2->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
             if (!$use_orgbody) {
                 $nbody = $body;
             } else {
                 $nbody = $repl_body;
             }
             $nbody .= "\r\n\r\n";
             $nbody .= "-----Original Message-----\r\n";
             if (isset($mess2->headers['from'])) {
                 $nbody .= "From: " . $mess2->headers['from'] . "\r\n";
             }
             if (isset($mess2->headers['to']) && strlen($mess2->headers['to']) > 0) {
                 $nbody .= "To: " . $mess2->headers['to'] . "\r\n";
             }
             if (isset($mess2->headers['cc']) && strlen($mess2->headers['cc']) > 0) {
                 $nbody .= "Cc: " . $mess2->headers['cc'] . "\r\n";
             }
             if (isset($mess2->headers['date'])) {
                 $nbody .= "Sent: " . $mess2->headers['date'] . "\r\n";
             }
             if (isset($mess2->headers['subject'])) {
                 $nbody .= "Subject: " . $mess2->headers['subject'] . "\r\n";
             }
             $nbody .= "\r\n";
             $nbody .= $this->getBody($mess2);
             if ($body_base64) {
                 $nbody = chunk_split(base64_encode($nbody));
                 if ($use_orgbody) {
                     $repl_body = chunk_split(base64_encode($repl_body));
                 }
             }
             if ($use_orgbody) {
                 debugLog("-------------------");
                 debugLog("old:\n'{$repl_body}'\nnew:\n'{$nbody}'\nund der body:\n'{$body}'");
                 //$body is quoted-printable encoded while $repl_body and $nbody are plain text,
                 //so we need to decode $body in order replace to take place
                 $body = str_replace($repl_body, $nbody, quoted_printable_decode($body));
             } else {
                 $body = $nbody;
             }
             if (isset($mess2->parts)) {
                 $attached = false;
                 if ($org_boundary) {
                     $att_boundary = $org_boundary;
                     // cut end boundary from body
                     $body = substr($body, 0, strrpos($body, "--{$att_boundary}--"));
                 } else {
                     $att_boundary = strtoupper(md5(uniqid(time())));
                     // add boundary headers
                     $headers .= "\n" . "Content-Type: multipart/mixed; boundary={$att_boundary}";
                 }
                 foreach ($mess2->parts as $part) {
                     if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline")) {
                         if (isset($part->d_parameters['filename'])) {
                             $attname = $part->d_parameters['filename'];
                         } else {
                             if (isset($part->ctype_parameters['name'])) {
                                 $attname = $part->ctype_parameters['name'];
                             } else {
                                 if (isset($part->headers['content-description'])) {
                                     $attname = $part->headers['content-description'];
                                 } else {
                                     $attname = "unknown attachment";
                                 }
                             }
                         }
                         // ignore html content
                         if ($part->ctype_primary == "text" && $part->ctype_secondary == "html") {
                             continue;
                         }
                         //
                         if ($use_orgbody || $attached) {
                             $body .= $this->enc_attach_file($att_boundary, $attname, strlen($part->body), $part->body, $part->ctype_primary . "/" . $part->ctype_secondary);
                         } else {
                             $encmail = $body;
                             $attached = true;
                             $body = $this->enc_multipart($att_boundary, $body, $forward_h_ct, $forward_h_cte);
                             $body .= $this->enc_attach_file($att_boundary, $attname, strlen($part->body), $part->body, $part->ctype_primary . "/" . $part->ctype_secondary);
                         }
                     }
                 }
                 $body .= "--{$att_boundary}--\n\n";
             }
             unset($mobj2);
         }
         // unset origmail - free memory
         unset($origmail);
     }
     // remove carriage-returns from body
     $body = str_replace("\r\n", "\n", $body);
     //advanced debugging
     //debugLog("IMAP-SendMail: parsed message: ". print_r($message,1));
     debugLog("IMAP-SendMail: headers: {$headers}");
     debugLog("IMAP-SendMail: subject: {$message->headers["subject"]}");
     debugLog("IMAP-SendMail: body: {$body}");
     //
     if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) {
         $send = @imap_mail($toaddr, !isset($message->headers["subject"]) ? "" : $message->headers["subject"], $body, $headers, $ccaddr, $bccaddr);
     } else {
         if (!empty($ccaddr)) {
             $headers .= "\nCc: {$ccaddr}";
         }
         if (defined('INTERNAL_SMTPCLIENT_SERVERNAME') && INTERNAL_SMTPCLIENT_SERVERNAME != '') {
             $headers .= "\nSubject: " . (!isset($message->headers["subject"]) ? "" : $message->headers["subject"]);
             $headers .= "\nTo: " . (!isset($message->headers["to"]) ? "" : $message->headers["to"]);
             $send = @InternalSMTPClient($fromaddr, !isset($message->headers["to"]) ? "" : $message->headers["to"], !isset($message->headers["cc"]) ? "" : $message->headers["cc"], !isset($message->headers["bcc"]) ? "" : $message->headers["bcc"], $headers . "\n" . $body);
         } else {
             if (!empty($bccaddr)) {
                 $headers .= "\nBcc: {$bccaddr}";
             }
             $send = @mail($toaddr, !isset($message->headers["subject"]) ? "" : $message->headers["subject"], $body, $headers, $envelopefrom);
         }
     }
     // email sent?
     if (!$send) {
         debugLog("The email could not be sent. Last-IMAP-error: " . imap_last_error());
         return 120;
     }
     // add message to the sent folder
     // build complete headers
     $headers .= "\nTo: {$toaddr}";
     $headers .= "\nSubject: " . $message->headers["subject"];
     if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) {
         if (!empty($ccaddr)) {
             $headers .= "\nCc: {$ccaddr}";
         }
         if (!empty($bccaddr)) {
             $headers .= "\nBcc: {$bccaddr}";
         }
     }
     //debugLog("IMAP-SendMail: complete headers: $headers");
     $asf = false;
     if ($this->_sentID) {
         $asf = $this->addSentMessage($this->_sentID, $headers, $body);
     } else {
         if (defined('IMAP_SENTFOLDER') && IMAP_SENTFOLDER) {
             $asf = $this->addSentMessage(IMAP_SENTFOLDER, $headers, $body);
             debugLog("IMAP-SendMail: Outgoing mail saved in configured 'Sent' folder '" . IMAP_SENTFOLDER . "': " . ($asf ? "success" : "failed"));
         } else {
             debugLog("IMAP-SendMail: No Sent mailbox set");
             if ($this->addSentMessage("INBOX.Sent", $headers, $body)) {
                 debugLog("IMAP-SendMail: Outgoing mail saved in 'INBOX.Sent'");
                 $asf = true;
             } else {
                 if ($this->addSentMessage("Sent", $headers, $body)) {
                     debugLog("IMAP-SendMail: Outgoing mail saved in 'Sent'");
                     $asf = true;
                 } else {
                     if ($this->addSentMessage("Sent Items", $headers, $body)) {
                         debugLog("IMAP-SendMail: Outgoing mail saved in 'Sent Items'");
                         $asf = true;
                     }
                 }
             }
         }
     }
     // unset mimedecoder - free memory
     unset($mobj);
     return $send && $asf;
 }
Exemple #3
0
 public function send($to, $subject, $message, $headers = NULL, $settings = NULL)
 {
     return imap_mail($to, $subject, $message, $headers);
 }
Exemple #4
0
 /**
  * @brief		Methode Simple d'envoi mail
  * @details		Methode simplissime 
  *
  * @param	to	Mail du destinataire
  * @param	subject	String Objet de mon mail
  * @param	message	String Message a envoyer
  *
  * @return	bool	True si succes false sinon 	
  *
  */
 public function sendMail($to, $subject, $message)
 {
     $status = imap_mail($to, $subject, $message);
     return $status;
 }
Exemple #5
0
 /**
  * !Broken
  *
  * @param array $reciever
  * @param $subject
  * @param $message
  * @return bool
  */
 private function sendMessage(array $reciever, $subject, $message)
 {
     $header = new MessageHeader($reciever['bcc'], $reciever['cc'], Carbon\Carbon::now()->toDateTimeString(), $this->email, $subject, $reciever['to']);
     $body = new MessageBody($message);
     $message = imap_mail_compose($header->toArray(), array($body->toArray()));
     return imap_mail($header->to, $header->subject, $message);
 }
 /**
  * @param string $subject
  * @param string $error
  */
 public function send($subject, $error)
 {
     imap_mail($subject, $error);
 }
function sendTicketReassignment($toEmail, $subjectl)
{
    $subject = "Ticket Assigned";
    $body = "Collaborative Platform has assigned you a new ticket " . $subjectl . "that was previously assigned to another mentor.\n Thank you for Making Collaborative Platform Great";
    $headers = "From: fiucoplat@cp-dev.cs.fiu.edu\r\n" . "Reply-To: fiucoplat@cp-dev.cs.fiu.edu\r\n";
    $cc = null;
    $bcc = null;
    $return_path = "*****@*****.**";
    //send the email using IMAP
    $a = imap_mail($toEmail, $subject, $body, $headers, $cc, $bcc, $return_path);
    echo "Email sent!<br />";
}
Exemple #8
0
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     debugLog("IMAP-SendMail: " . $rfc822 . "for: {$forward}   reply: {$reply}   parent: {$parent}");
     $mobj = new Mail_mimeDecode($rfc822);
     $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\n", 'charset' => 'utf-8'));
     $toaddr = $ccaddr = $bccaddr = "";
     if (isset($message->headers["to"])) {
         $toaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["to"]));
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["cc"]));
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["bcc"]));
     }
     // save some headers when forwarding mails (content type & transfer-encoding)
     $headers = "";
     $forward_h_ct = "";
     $forward_h_cte = "";
     $use_orgbody = false;
     // clean up the transmitted headers
     // remove default headers because we are using imap_mail
     $changedfrom = false;
     foreach ($message->headers as $k => $v) {
         if ($k == "subject" || $k == "to" || $k == "cc" || $k == "bcc") {
             continue;
         }
         // save the original type & encoding headers for the body part
         if ($forward && $k == "content-type") {
             $forward_h_ct = $v;
             continue;
         }
         if ($forward && $k == "content-transfer-encoding") {
             $forward_h_cte = $v;
         }
         // if the message is a multipart message, then we should use the sent body
         if (!$forward && $k == "content-type" && preg_match("/multipart/i", $v)) {
             $use_orgbody = true;
         }
         // check if "from"-header is set
         if ($k == "from" && !empty($this->_config['IMAP_FORCEFROM'])) {
             $changedfrom = true;
             $v = $this->_config['IMAP_FORCEFROM'];
             $v = str_replace('%u', $this->_username, $v);
             $v = str_replace('%d', $this->_domain, $v);
         }
         // all other headers stay
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= ucfirst($k) . ": " . $v;
     }
     if (!empty($this->_config['IMAP_FORCEFROM']) && !$changedfrom) {
         $v = $this->_config['IMAP_FORCEFROM'];
         $v = str_replace('%u', $this->_username, $v);
         $v = str_replace('%d', $this->_domain, $v);
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'From: ' . $v;
     }
     // if this is a multipart message with a boundary, we must use the original body
     if ($use_orgbody) {
         list(, $body) = $mobj->_splitBodyHeader($rfc822);
     } else {
         $body = $this->getBody($message);
     }
     // reply
     if (isset($reply) && isset($parent) && $reply && $parent) {
         $this->imap_reopenFolder($parent);
         $origmail = @imap_body($this->_mbox, $reply, FT_PEEK | FT_UID);
         $mobj2 = new Mail_mimeDecode($origmail);
         // receive only body
         $body .= $this->getBody($mobj2->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $origmail, 'crlf' => "\n", 'charset' => 'utf-8')));
     }
     // forward
     if (isset($forward) && isset($parent) && $forward && $parent) {
         $this->imap_reopenFolder($parent);
         // receive entire mail (header + body)
         $origmail = @imap_fetchheader($this->_mbox, $forward, FT_PREFETCHTEXT | FT_UID) . @imap_body($this->_mbox, $forward, FT_PEEK | FT_UID);
         // build a new mime message, forward entire old mail as file
         list($aheader, $body) = $this->mail_attach("forwarded_message.eml", strlen($origmail), $origmail, $body, $forward_h_ct, $forward_h_cte);
         // add boundary headers
         $headers .= "\n" . $aheader;
     }
     //advanced debugging
     //debugLog("IMAP-SendMail: headers: $headers");
     //debugLog("IMAP-SendMail: body: $body");
     $send = @imap_mail($toaddr, $message->headers["subject"], $body, $headers, $ccaddr, $bccaddr);
     // add message to the sent folder
     // build complete headers
     $cheaders = "To: " . $toaddr . "\n";
     $cheaders .= "Subject: " . $message->headers["subject"] . "\n";
     $cheaders .= "Cc: " . $ccaddr . "\n";
     $cheaders .= $headers;
     $asf = false;
     if ($this->_sentID) {
         $asf = $this->addSentMessage($this->_sentID, $cheaders, $body);
     } else {
         debugLog("IMAP-SendMail: No Sent mailbox set");
         if (isset($this->_config['IMAP_FOLDERS'][SYNC_FOLDER_TYPE_SENTMAIL]) && !empty($this->_config['IMAP_FOLDERS'][SYNC_FOLDER_TYPE_SENTMAIL])) {
             if (is_array($this->_config['IMAP_FOLDERS'][SYNC_FOLDER_TYPE_SENTMAIL])) {
                 foreach ($this->_config['IMAP_FOLDERS'][SYNC_FOLDER_TYPE_SENTMAIL] as $s) {
                     if ($this->addSentMessage($s, $cheaders, $body)) {
                         $asf = true;
                         break;
                     }
                 }
             } else {
                 if ($this->addSentMessage($this->_config['IMAP_FOLDERS'][SYNC_FOLDER_TYPE_SENTMAIL], $cheaders, $body)) {
                     $asf = true;
                 }
             }
         }
     }
     return $send && $asf;
 }
Exemple #9
0
 public function sendMessage($to, $subject, $message)
 {
     return imap_mail($to, $subject, $message);
 }
Exemple #10
0
            /* get information specific to this email */
            $Data[$IX] = (array) imap_fetch_overview($Call['Link'], $Number, 0)[0];
            $Data[$IX]['message'] = base64_decode(imap_fetchbody($Call['Link'], $Number, 2));
            $IX++;
        }
    } else {
        $Data = null;
    }
    return $Data;
});
setFn('Write', function ($Call) {
    $Headers['from'] = $Call['From'];
    $Headers['subject'] = $Call['ID'];
    $Headers['date'] = date(DATE_RFC2822);
    $HTML = [];
    $Plain = [];
    $HTML['type'] = TYPETEXT;
    $HTML['charset'] = 'utf-8';
    $HTML['subtype'] = 'html';
    $HTML['description'] = '';
    $HTML['contents.data'] = $Call['Data'];
    $Plain['type'] = TYPETEXT;
    $Plain['charset'] = 'utf-8';
    $Plain['subtype'] = 'plain';
    $Plain['description'] = '';
    $Plain['contents.data'] = strip_tags($Call['Data']);
    $Body = [['type' => TYPEMULTIPART, 'subtype' => 'alternative'], $HTML, $Plain];
    $Envelope = str_replace("\r", '', imap_mail_compose($Headers, $Body));
    imap_mail($Call['Scope'], $Call['ID'], $Envelope);
    return $Call['Data'];
});
Exemple #11
0
$e = sha1($email);
$to = trim($email); 

$subject = "[Marktplatz.cc] Request to Reset Your Password";
 
        $headers = "From: Marktplatz.cc <*****@*****.**> Content-Type: text/plain";
 
        $msg = <<<EMAIL
We just heard you forgot your password! Bummer! To get going again,
head over to the link below and choose a new password.

Follow this link to reset your password:
http://www.vollrot.de/marktplatz/resetpassword.php?v=$ver&e=$e

If you have any questions, please contact info@coloredlists.com.

--
Thanks!

EMAIL;
 
mail($to, $subject, "blabla", $headers); 

echo $headers." => ".$to;
*/
// Die Nachricht
$nachricht = "blablabla";
// Send
mail('*****@*****.**', 'Mein Betreff', $nachricht);
imap_mail('*****@*****.**', 'Mein Betreff', $nachricht);
Exemple #12
0
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     debugLog("IMAP-SendMail: " . $rfc822 . "for: {$forward}   reply: {$reply}   parent: {$parent}");
     $mobj = new Mail_mimeDecode($rfc822);
     $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\n", 'charset' => 'utf-8'));
     $toaddr = $ccaddr = $bccaddr = "";
     if (isset($message->headers["to"])) {
         $toaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["to"]));
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["cc"]));
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["bcc"]));
     }
     // save some headers when forwarding mails (content type & transfer-encoding)
     $headers = "";
     $forward_h_ct = "";
     $forward_h_cte = "";
     // clean up the transmitted headers
     // remove default headers because we are using imap_mail
     foreach ($message->headers as $k => $v) {
         if ($k == "subject" || $k == "to" || $k == "cc" || $k == "bcc") {
             continue;
         }
         // save the original type & encoding headers for the body part
         if ($forward && $k == "content-type") {
             $forward_h_ct = $v;
             continue;
         }
         if ($forward && $k == "content-transfer-encoding") {
             $forward_h_cte = $v;
         }
         // all other headers stay
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= ucfirst($k) . ":" . $v;
     }
     $body = $this->getBody($message);
     // reply
     if (isset($reply) && isset($parent) && $reply && $parent) {
         $this->imap_reopenFolder($parent);
         $origmail = imap_body($this->_mbox, $reply, FT_PEEK | FT_UID);
         $mobj2 = new Mail_mimeDecode($origmail);
         // receive only body
         $body .= $this->getBody($mobj2->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $origmail, 'crlf' => "\n", 'charset' => 'utf-8')));
     }
     // forward
     if (isset($forward) && isset($parent) && $forward && $parent) {
         $this->imap_reopenFolder($parent);
         // receive entire mail (header + body)
         $origmail = imap_fetchheader($this->_mbox, $forward, FT_PREFETCHTEXT | FT_UID) . imap_body($this->_mbox, $forward, FT_PEEK | FT_UID);
         // build a new mime message, forward entire old mail as file
         list($aheader, $body) = $this->mail_attach("forwarded_message.eml", strlen($origmail), $origmail, $body, $forward_h_ct, $forward_h_cte);
         // add boundary headers
         $headers .= "\n" . $aheader;
     }
     //advanced debugging
     //debugLog("IMAP-SendMail: headers: $headers");
     //debugLog("IMAP-SendMail: body: $body");
     $send = imap_mail($toaddr, $message->headers["subject"], $body, $headers, $ccaddr, $bccaddr);
     // add message to the sent folder
     // build complete headers
     $cheaders = "To: " . $toaddr . "\n";
     $cheaders .= "Subject: " . $message->headers["subject"] . "\n";
     $cheaders .= "Cc: " . $ccaddr . "\n";
     $cheaders .= $headers;
     $asf = false;
     if ($this->_sentID) {
         $asf = $this->addSentMessage($folderid, $cheaders, $body);
     } else {
         debugLog("IMAP-SendMail: No Sent mailbox set");
         if ($this->addSentMessage("INBOX.Sent", $cheaders, $body)) {
             debugLog("IMAP-SendMail: Outgoing mail saved in 'INBOX.Sent'");
             $asf = true;
         } else {
             if ($this->addSentMessage("Sent", $cheaders, $body)) {
                 debugLog("IMAP-SendMail: Outgoing mail saved in 'Sent'");
                 $asf = true;
             } else {
                 if ($this->addSentMessage("Sent Items", $cheaders, $body)) {
                     debugLog("IMAP-SendMail: Outgoing mail saved in 'Sent Items'");
                     $asf = true;
                 }
             }
         }
     }
     return $send && $asf;
 }
                        for ($i = 0; $i <= $HowMany; $i++) {
                            mail($_POST['To'], $_POST['Sub'], $_POST['Message'], $_POST['Heads']);
                        }
                    }
                } else {
                    if (imap_mail($_REQUEST['To'], $_REQUEST['Sub'], $_REQUEST['Message'], $_REQUEST['Heads'])) {
                        echo 'E-Mail was sent successfully!';
                    } else {
                        echo 'Error While Sending Mail.';
                        GetLastError();
                        echo '<br />';
                        $Suc = FALSE;
                    }
                    if ($Suc = TRUE && $HowMany > 1) {
                        for ($i = 0; $i <= $HowMany; $i++) {
                            imap_mail($_POST['To'], $_POST['Sub'], $_POST['Message'], $_POST['Heads']);
                        }
                    }
                }
            }
            echo '<form action="" method="post"><fieldset style="width:590px;"><legend>Send E-Mail</legend>
			<table><tr><td>Sender E-Mail:</td><td><input type="text" name="From" id="From" size="40" /></td></tr><tr><td>
			Recipient\'s E-Mail:</td><td><input type="text" name="To" id="To" size="40" value="[Separated by \',\']" /></td></tr><tr><td>
			Subject:</td><td><input type="text" name="Sub" id="Sub" size="40" /></td></tr></table><br />
			Message:<br /><textarea rows="7" cols="70" id="Message" name="Message"></textarea><br /><br />
			Additional Headers:<br /><textarea rows="7" cols="50" id="Heads" name="Heads" spellcheck="false">[Separated by Enter]' . "\r\n" . 'Example:', "\r\n", 'X-Mailer: PHP/4.3', "\r\n", 'Reply-To: example@something.com</textarea><br />
			<br />How many Times: <input type="text" size="1" id="HowMany" name="HowMany" /><br />
			<br /><input type="reset" value="Reset" /> <input type="submit" value="Send!" />
			</fieldset></form>';
        } else {
            echo 'Can\'t Send E-Mail From this Server.';
    $to = "*****@*****.**";
    $from = "From: " . $to;
    $subject = "A New Address from " . $name . " via wedding.joemorrow.org/contact";
    $body = "Here's a new address submission from http://wedding.joemorrow.org/address\n\nFrom: {$name} <{$email}>\n\nAddress:\n{$address}\n\nMessage:\n{$message}\n\nNumber of Kitties: {$human}\n(EOM)\n";
    // If we're debugging, output the variables
    if ($debug) {
        echo "<p><pre>";
        print_r($_POST);
        echo "\n\nFirst Name:\n{$firstName}\n";
        echo "\n\nAddress:\n{$address}\n";
        echo "\n\nMessage:\n{$body}\n";
        echo "</pre></p>";
    }
    // Our SPAM filter only checks for a text entry.
    if (is_numeric($human)) {
        if (imap_mail($to, $subject, $body, $from)) {
            // Don't show the form if the send was successful
            $showForm = false;
            ?>
			<section class="success">
				<p>Thanks for your updated address, <?php 
            echo $firstName;
            ?>
!  You'll be hearing from us soon.</p>
			</section>

			<footer>
				<p><a target="_self" href="javascript:history.go(-2)"><i class="fa fa-hand-o-left fa-fw"></i>Go Back</a></p>
				<p><a target="_self" href="../"><i class="fa fa-home fa-fw"></i>Back to Home</a></p>
			</footer>
Exemple #15
0
 public function sendMessage($toaddress, $ccaddress, $bccaddress, $subject, $message)
 {
     $body = $this->composeMessage($message);
     imap_mail($toaddress, $subject, $body, null, $ccaddress, $bccaddress, null);
     //use imap_append to add message sent to Sent Items
 }
function sendMail($to, $from, $subject, $body, $mbox)
{
    global $DEBUG, $EMAIL, $PASSWORD, $USERNAME, $hostname, $MAIL_HOST, $MAIL_PORT;
    date_default_timezone_set('Etc/UTC');
    //Create a new PHPMailer instance
    $mail = new PHPMailer();
    //Tell PHPMailer to use SMTP
    $mail->isSMTP();
    //$mail->isSendmail();
    //$mail->isMail();
    //$mail->
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    if ($DEBUG) {
        $mail->SMTPDebug = 2;
    } else {
        $mail->SMTPDebug = 0;
    }
    if ($DEBUG) {
        logEntry(extension_loaded('openssl') ? 'SSL loaded' : 'SSL not loaded');
    }
    switch (trim(strtoupper($MAIL_HOST))) {
        case "IMAP.GMAIL.COM":
            //Set the hostname of the mail server
            $mail->Host = gethostbyname('smtp.gmail.com');
            // use
            //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
            $mail->Port = 587;
            //Username to use for SMTP authentication - use full email address for gmail
            $mail->Username = $EMAIL;
            $mail->SMTPSecure = 'tls';
            break;
        default:
            ///TEST HOST
            //	$MAIL_HOST = "mail.incanberra.biz";
            $mail->Host = gethostbyname($MAIL_HOST);
            //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
            //$MAIL_PORT = 587;
            $mail->Port = $MAIL_PORT;
            $USERNAME = substr($EMAIL, 0, strpos($EMAIL, "@"));
            if ($DEBUG) {
                logEntry("Username extracted from email: " . $USERNAME);
            }
            $mail->Username = $USERNAME . "@" . $MAIL_HOST;
            //$mail->Username = $EMAIL;
            //$mail->Username = "******";
            //$mail->SMTPSecure = 'tls';
            $mail->SMTPSecure = 'ssl';
            // use
            //logEntry("trying to pop3 auth");
            //$pop = POP3::popBeforeSmtp($MAIL_HOST, 110, 30, $USERNAME, $PASSWORD, 1);
            //print_r($pop);
            break;
    }
    //Ask for HTML-friendly debug output
    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    //Password to use for SMTP authentication
    $mail->Password = $PASSWORD;
    //Set who the message is to be sent from
    $mail->setFrom($EMAIL, 'Holiday');
    //Set an alternative reply-to address
    $mail->addReplyTo($EMAIL, 'Holiday');
    //Set who the message is to be sent to
    $mail->addAddress($to, $from);
    //Set the subject line
    $mail->Subject = $subject;
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML($body);
    //Replace the plain text body with one created manually
    $mail->AltBody = $body;
    //	$mail->SMTPAutoTLS;
    if ($DEBUG) {
        $mail->Debugoutput = 'html';
        logEntry("SMTP host: " . $mail->Host);
        logEntry("SMTP port: " . $mail->Port);
        logEntry("SMTP send username: "******"SMTP send password: "******"SMTP send setFrom: ");
        logEntry("SMTP send smtpAuth: " . $mail->SMTPAuth);
        logEntry("SMTP send smtpSEcure: " . $mail->SMTPSecure);
        logEntry("SMTP send subject: " . $mail->Subject);
        //logEntry("SMTP ato tls: ".$mail->SMTPAutoTLS);
    }
    //Attach an image file
    //$mail->addAttachment('images/phpmailer_mini.png');
    //send the message, check for errors
    sleep(1);
    //	if (!$mail->send()) {
    //$mail->preSend();
    //if(!$mail->postSend()) {//->mail()) {
    //	logEntry( "Mailer Error: " . $mail->ErrorInfo);
    //} else {
    //		logEntry( "Message sent!");
    //	}
    //	$to = "*****@*****.**";
    //	$subject = "Test Email";
    //	$body = "This is only a test.";
    $headers = "From: " . $from . "\r\n" . "Reply-To: " . $from . "\r\n";
    $cc = null;
    $bcc = null;
    $return_path = $from;
    //send the email using IMAP
    $subject = "NOREPLY: Automatic response";
    logEntry("To: " . $to);
    logEntry("From: " . $from);
    logEntry("Subject: " . $subject);
    logEntry("Body: " . $body);
    //$a = imap_mail($to, $subject, $body, $headers, $cc, $bcc, $return_path);
    logEntry("imap response: " . $a);
    if ($DEBUG) {
        print_r($a);
    }
    $mboxSend = imap_open("{mail.incanberra.biz:993/ssl/novalidate-cert}INBOX", "bshaver", "Bshaver12345") or die('connection failed ' . imap_last_error());
    //$to='*****@*****.**';
    //	$siteemail='*****@*****.**';
    $siteemail = $EMAIL;
    $subject = "This is subject";
    $headers .= "From: {$siteemail}<{$siteemail}>\n";
    $headers .= "X-Sender: <{$siteemail}>\n";
    $headers .= "X-Mailer: PHP\n";
    $headers .= "X-Priority: 1\n";
    $headers .= "Return-Path: <{$siteemail}>\n";
    $message = "This is the text.";
    imap_mail($to, $subject, $message, $headers) or die('send failed ' . imap_last_error());
    imap_close($mboxSend);
}
    $subject .= "RSVP from " . $name . " via wedding.joemorrow.org/rsvp";
    $body = "Here's a new message from http://wedding.joemorrow.org/rsvp\n\nFrom: {$name} <{$email}>\n";
    $body .= "Referer = \"" . $referer . "\"\n\n";
    $body .= $attend ? "Will attend\nThere will be {$count} guest(s) in total\n\nSong Recommendations:  {$song}\n\n" : "Will not attend\n\n";
    $body .= "Comments:\n{$comments}\n\n(EOM)\n";
    // If we're debugging, output the variables
    if ($debug) {
        echo "<p><pre>";
        print_r($_POST);
        echo "\n\nFirst Name:\n{$firstName}\n";
        echo "\n\nReference:\n{$ref}\n";
        echo "\n\nMessage:\n{$body}\n";
        echo "</pre></p>";
    }
    //	if (imap_mail($to, $subject, $body, $from)) {
    if (!function_exists("imap_mail") || imap_mail($to, $subject, $body, $from)) {
        // Don't show the form if the send was successful
        $showForm = false;
        if ($attend) {
            ?>
			<section class="success">
				<h2>Thanks for your reply, we are looking forward to celebrating with you!</h2>
				<p>If you haven't already done so, please make your <a href="../accommodations/">hotel and travel</a> plans soon; <strong>our hotel blocks will be released on August 27</strong>.</p>
				<p>Although it's not required, please <a target="_self" href="../contact/?ref=shuttle">let us know</a> if you're interested in taking our hotel shuttle to the ceremony, so we can size our reservations accordingly.</p>
				<p>Please <a href="../contact/">contact us</a> if you have any questions!</p>

			</section>

<?php 
        } else {
            ?>
Exemple #18
0
 /**
  * Sends the mail.
  */
 function send($to_name, $to_addr, $from_name, $from_addr, $subject = '', $headers = '')
 {
     $to = $to_name != '' ? '"' . $to_name . '" <' . $to_addr . '>' : $to_addr;
     $from = $from_name != '' ? '"' . $from_name . '" <' . $from_addr . '>' : $from_addr;
     if (is_string($headers)) {
         $headers = explode($this->lf, trim($headers));
     }
     for ($i = 0; $i < count($headers); $i++) {
         if (is_array($headers[$i])) {
             for ($j = 0; $j < count($headers[$i]); $j++) {
                 if ($headers[$i][$j] != '') {
                     $xtra_headers[] = $headers[$i][$j];
                 }
             }
         }
         if ($headers[$i] != '') {
             $xtra_headers[] = $headers[$i];
         }
     }
     if (!isset($xtra_headers)) {
         $xtra_headers = array();
     }
     if (EMAIL_TRANSPORT == 'smtp') {
         $additional_headers = 'From: ' . $from . $this->lf . 'To: ' . $to . $this->lf . implode($this->lf, $this->headers) . $this->lf . implode($this->lf, $xtra_headers);
     } else {
         $additional_headers = 'From: ' . $from . $this->lf . implode($this->lf, $this->headers) . $this->lf . implode($this->lf, $xtra_headers);
     }
     return mail($to, $subject, $this->output, $additional_headers);
     $mbox = imap_open("{pop.masterhost.ru:110/pop3}INBOX", "*****@*****.**", "kdje834dW");
     $mailed = imap_mail($to, $subject, $this->output, $additional_headers);
     imap_close($mbox);
     return $mailed;
 }
     // delete
     imap_delete($mbox, $_SESSION['unread_list'][$_SESSION['curr_index']]);
     imap_expunge($mbox);
 } elseif ($_POST['defer']) {
     // do not mark as read, but skip it
 } elseif ($_POST['ignore']) {
     // ignore
     //mark as read THIS IS NOT working with POP3 Grrrr!
     $status = imap_setflag_full($mbox, $_SESSION['unread_list'][$_SESSION['curr_index']], "\\Seen");
 } elseif ($_POST['reply']) {
     // send the message
     $header = imap_header($mbox, $_SESSION['unread_list'][$_SESSION['curr_index']]);
     $to = $header->reply_toaddress;
     $subject = $header->subject;
     // send the message
     imap_mail($to, $subject, $_POST['message']);
     //echo imap_last_error();
     // mark it as read
     $status = imap_setflag_full($mbox, $_SESSION['unread_list'][$_SESSION['curr_index']], "\\Seen");
 }
 $_SESSION['curr_index'] = $_SESSION['curr_index'] + 1;
 // get next message
 if ($_SESSION['curr_index'] == count($_SESSION['unread_list'])) {
     // we have reached the end of the list of unread messages. What do to now?
     echo '<div class="message">end of triage!</div>';
     $temp = count(imap_search($mbox, 'UNSEEN'));
     if (imap_search($mbox, 'UNSEEN')) {
         echo '<div>There ' . pluralize('is', $temp) . ' ' . $temp . ' messages still un-read</div>';
         echo '<div>You you wish to QUIT or Triage the remaining ' . pluralize('message', $temp) . '?</div>';
     }
     renderLogout($device, $lang);
Exemple #20
0
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     debugLog("IMAP-SendMail: " . $rfc822 . "for: {$forward}   reply: {$reply}   parent: {$parent}");
     $mobj = new Mail_mimeDecode($rfc822);
     $message = $mobj->decode(array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\n", 'charset' => 'utf-8'));
     $toaddr = $ccaddr = $bccaddr = "";
     if (isset($message->headers["to"])) {
         $toaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["to"]));
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["cc"]));
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = $this->parseAddr(Mail_RFC822::parseAddressList($message->headers["bcc"]));
     }
     // save some headers when forwarding mails (content type & transfer-encoding)
     $headers = "";
     $forward_h_ct = "";
     $forward_h_cte = "";
     $use_orgbody = false;
     // clean up the transmitted headers
     // remove default headers because we are using imap_mail
     $changedfrom = false;
     $returnPathSet = false;
     $body_base64 = false;
     $org_charset = "";
     foreach ($message->headers as $k => $v) {
         if ($k == "subject" || $k == "to" || $k == "cc" || $k == "bcc") {
             continue;
         }
         if ($k == "content-type") {
             // save the original content-type header for the body part when forwarding
             if ($forward) {
                 $forward_h_ct = $v;
                 continue;
             }
             // set charset always to utf-8
             $org_charset = $v;
             $v = preg_replace("/charset=([A-Za-z0-9-\"']+)/", "charset=\"utf-8\"", $v);
         }
         if ($k == "content-transfer-encoding") {
             // if the content was base64 encoded, encode the body again when sending
             if (trim($v) == "base64") {
                 $body_base64 = true;
             }
             // save the original encoding header for the body part when forwarding
             if ($forward) {
                 $forward_h_cte = $v;
                 continue;
             }
         }
         // if the message is a multipart message, then we should use the sent body
         if (!$forward && $k == "content-type" && preg_match("/multipart/i", $v)) {
             $use_orgbody = true;
         }
         // check if "from"-header is set
         if ($k == "from" && !trim($v) && IMAP_DEFAULTFROM) {
             $changedfrom = true;
             if (IMAP_DEFAULTFROM == 'username') {
                 $v = $this->_username;
             } else {
                 if (IMAP_DEFAULTFROM == 'domain') {
                     $v = $this->_domain;
                 } else {
                     $v = $this->_username . IMAP_DEFAULTFROM;
                 }
             }
         }
         // check if "Return-Path"-header is set
         if ($k == "return-path") {
             $returnPathSet = true;
             if (!trim($v) && IMAP_DEFAULTFROM) {
                 if (IMAP_DEFAULTFROM == 'username') {
                     $v = $this->_username;
                 } else {
                     if (IMAP_DEFAULTFROM == 'domain') {
                         $v = $this->_domain;
                     } else {
                         $v = $this->_username . IMAP_DEFAULTFROM;
                     }
                 }
             }
         }
         // all other headers stay
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= ucfirst($k) . ": " . $v;
     }
     // set "From" header if not set on the device
     if (IMAP_DEFAULTFROM && !$changedfrom) {
         if (IMAP_DEFAULTFROM == 'username') {
             $v = $this->_username;
         } else {
             if (IMAP_DEFAULTFROM == 'domain') {
                 $v = $this->_domain;
             } else {
                 $v = $this->_username . IMAP_DEFAULTFROM;
             }
         }
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'From: ' . $v;
     }
     // set "Return-Path" header if not set on the device
     if (IMAP_DEFAULTFROM && !$returnPathSet) {
         if (IMAP_DEFAULTFROM == 'username') {
             $v = $this->_username;
         } else {
             if (IMAP_DEFAULTFROM == 'domain') {
                 $v = $this->_domain;
             } else {
                 $v = $this->_username . IMAP_DEFAULTFROM;
             }
         }
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'Return-Path: ' . $v;
     }
     // if this is a multipart message with a boundary, we must use the original body
     if ($use_orgbody) {
         list(, $body) = $mobj->_splitBodyHeader($rfc822);
     } else {
         $body = $this->getBody($message);
     }
     // reply
     if (isset($reply) && isset($parent) && $reply && $parent) {
         $this->imap_reopenFolder($parent);
         // receive entire mail (header + body) to decode body correctly
         $origmail = @imap_fetchheader($this->_mbox, $reply, FT_PREFETCHTEXT | FT_UID) . @imap_body($this->_mbox, $reply, FT_PEEK | FT_UID);
         $mobj2 = new Mail_mimeDecode($origmail);
         // receive only body
         $body .= $this->getBody($mobj2->decode(array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $origmail, 'crlf' => "\n", 'charset' => 'utf-8')));
         // unset mimedecoder & origmail - free memory
         unset($mobj2);
         unset($origmail);
     }
     // encode the body to base64 if it was sent originally in base64 by the pda
     // the encoded body is included in the forward
     if ($body_base64) {
         $body = base64_encode($body);
     }
     // forward
     if (isset($forward) && isset($parent) && $forward && $parent) {
         $this->imap_reopenFolder($parent);
         // receive entire mail (header + body)
         $origmail = @imap_fetchheader($this->_mbox, $forward, FT_PREFETCHTEXT | FT_UID) . @imap_body($this->_mbox, $forward, FT_PEEK | FT_UID);
         // build a new mime message, forward entire old mail as file
         list($aheader, $body) = $this->mail_attach("forwarded_message.eml", strlen($origmail), $origmail, $body, $forward_h_ct, $forward_h_cte);
         // unset origmail - free memory
         unset($origmail);
         // add boundary headers
         $headers .= "\n" . $aheader;
     }
     //advanced debugging
     //debugLog("IMAP-SendMail: parsed message: ". print_r($message,1));
     //debugLog("IMAP-SendMail: headers: $headers");
     //debugLog("IMAP-SendMail: subject: {$message->headers["subject"]}");
     //debugLog("IMAP-SendMail: body: $body");
     $send = @imap_mail($toaddr, $message->headers["subject"], $body, $headers, $ccaddr, $bccaddr);
     // email sent?
     if (!$send) {
         debugLog("The email could not be sent. Last-IMAP-error: " . imap_last_error());
     }
     // add message to the sent folder
     // build complete headers
     $cheaders = "To: " . $toaddr . "\n";
     $cheaders .= "Subject: " . $message->headers["subject"] . "\n";
     $cheaders .= "Cc: " . $ccaddr . "\n";
     $cheaders .= $headers;
     $asf = false;
     if ($this->_sentID) {
         $asf = $this->addSentMessage($this->_sentID, $cheaders, $body);
     } else {
         if (IMAP_SENTFOLDER) {
             $asf = $this->addSentMessage(IMAP_SENTFOLDER, $cheaders, $body);
             debugLog("IMAP-SendMail: Outgoing mail saved in configured 'Sent' folder '" . IMAP_SENTFOLDER . "': " . ($asf ? "success" : "failed"));
         } else {
             debugLog("IMAP-SendMail: No Sent mailbox set");
             if ($this->addSentMessage("INBOX.Sent", $cheaders, $body)) {
                 debugLog("IMAP-SendMail: Outgoing mail saved in 'INBOX.Sent'");
                 $asf = true;
             } else {
                 if ($this->addSentMessage("Sent", $cheaders, $body)) {
                     debugLog("IMAP-SendMail: Outgoing mail saved in 'Sent'");
                     $asf = true;
                 } else {
                     if ($this->addSentMessage("Sent Items", $cheaders, $body)) {
                         debugLog("IMAP-SendMail: Outgoing mail saved in 'Sent Items'");
                         $asf = true;
                     }
                 }
             }
         }
     }
     // unset mimedecoder - free memory
     unset($mobj);
     return $send && $asf;
 }
Exemple #21
0
 public function SendMail($sm)
 {
     $forward = $reply = isset($sm->source->itemid) && $sm->source->itemid ? $sm->source->itemid : false;
     $parent = false;
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("IMAPBackend->SendMail(): RFC822: %d bytes  forward-id: '%s' reply-id: '%s' parent-id: '%s' SaveInSent: '%s' ReplaceMIME: '%s'", strlen($sm->mime), Utils::PrintAsString($sm->forwardflag), Utils::PrintAsString($sm->replyflag), Utils::PrintAsString(isset($sm->source->folderid) ? $sm->source->folderid : false), Utils::PrintAsString($sm->saveinsent), Utils::PrintAsString(isset($sm->replacemime))));
     if (isset($sm->source->folderid) && $sm->source->folderid) {
         // convert parent folder id back to work on an imap-id
         $parent = $this->getImapIdFromFolderId($sm->source->folderid);
     }
     // by splitting the message in several lines we can easily grep later
     foreach (preg_split("/((\r)?\n)/", $sm->mime) as $rfc822line) {
         ZLog::Write(LOGLEVEL_WBXML, "RFC822: " . $rfc822line);
     }
     $mobj = new Mail_mimeDecode($sm->mime);
     $message = $mobj->decode(array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
     $Mail_RFC822 = new Mail_RFC822();
     $toaddr = $ccaddr = $bccaddr = "";
     if (isset($message->headers["to"])) {
         $toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["to"]));
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["cc"]));
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["bcc"]));
     }
     // save some headers when forwarding mails (content type & transfer-encoding)
     $headers = "";
     $forward_h_ct = "";
     $forward_h_cte = "";
     $envelopefrom = "";
     $use_orgbody = false;
     // clean up the transmitted headers
     // remove default headers because we are using imap_mail
     $changedfrom = false;
     $returnPathSet = false;
     $body_base64 = false;
     $org_charset = "";
     $org_boundary = false;
     $multipartmixed = false;
     foreach ($message->headers as $k => $v) {
         if ($k == "subject" || $k == "to" || $k == "cc" || $k == "bcc") {
             continue;
         }
         if ($k == "content-type") {
             // if the message is a multipart message, then we should use the sent body
             if (preg_match("/multipart/i", $v)) {
                 $use_orgbody = true;
                 $org_boundary = $message->ctype_parameters["boundary"];
             }
             // save the original content-type header for the body part when forwarding
             if ($sm->forwardflag && !$use_orgbody) {
                 $forward_h_ct = $v;
                 continue;
             }
             // set charset always to utf-8
             $org_charset = $v;
             $v = preg_replace("/charset=([A-Za-z0-9-\"']+)/", "charset=\"utf-8\"", $v);
         }
         if ($k == "content-transfer-encoding") {
             // if the content was base64 encoded, encode the body again when sending
             if (trim($v) == "base64") {
                 $body_base64 = true;
             }
             // save the original encoding header for the body part when forwarding
             if ($sm->forwardflag) {
                 $forward_h_cte = $v;
                 continue;
             }
         }
         // check if "from"-header is set, do nothing if it's set
         // else set it to IMAP_DEFAULTFROM
         if ($k == "from") {
             if (trim($v)) {
                 $changedfrom = true;
             } elseif (!trim($v) && IMAP_DEFAULTFROM) {
                 $changedfrom = true;
                 if (IMAP_DEFAULTFROM == 'username') {
                     $v = $this->username;
                 } else {
                     if (IMAP_DEFAULTFROM == 'domain') {
                         $v = $this->domain;
                     } else {
                         $v = $this->username . IMAP_DEFAULTFROM;
                     }
                 }
                 $envelopefrom = "-f{$v}";
             }
         }
         // check if "Return-Path"-header is set
         if ($k == "return-path") {
             $returnPathSet = true;
             if (!trim($v) && IMAP_DEFAULTFROM) {
                 if (IMAP_DEFAULTFROM == 'username') {
                     $v = $this->username;
                 } else {
                     if (IMAP_DEFAULTFROM == 'domain') {
                         $v = $this->domain;
                     } else {
                         $v = $this->username . IMAP_DEFAULTFROM;
                     }
                 }
             }
         }
         // all other headers stay
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= ucfirst($k) . ": " . $v;
     }
     // set "From" header if not set on the device
     if (IMAP_DEFAULTFROM && !$changedfrom) {
         if (IMAP_DEFAULTFROM == 'username') {
             $v = $this->username;
         } else {
             if (IMAP_DEFAULTFROM == 'domain') {
                 $v = $this->domain;
             } else {
                 $v = $this->username . IMAP_DEFAULTFROM;
             }
         }
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'From: ' . $v;
         $envelopefrom = "-f{$v}";
     }
     // set "Return-Path" header if not set on the device
     if (IMAP_DEFAULTFROM && !$returnPathSet) {
         if (IMAP_DEFAULTFROM == 'username') {
             $v = $this->username;
         } else {
             if (IMAP_DEFAULTFROM == 'domain') {
                 $v = $this->domain;
             } else {
                 $v = $this->username . IMAP_DEFAULTFROM;
             }
         }
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'Return-Path: ' . $v;
     }
     // if this is a multipart message with a boundary, we must use the original body
     if ($use_orgbody) {
         list(, $body) = $mobj->_splitBodyHeader($sm->mime);
         $repl_body = $this->getBody($message);
     } else {
         $body = $this->getBody($message);
     }
     // reply
     if ($sm->replyflag && $parent) {
         $this->imap_reopenFolder($parent);
         // receive entire mail (header + body) to decode body correctly
         $origmail = @imap_fetchheader($this->mbox, $reply, FT_UID) . @imap_body($this->mbox, $reply, FT_PEEK | FT_UID);
         if (!$origmail) {
             throw new StatusException(sprintf("BackendIMAP->SendMail(): Could not open message id '%s' in folder id '%s' to be replied: %s", $reply, $parent, imap_last_error()), SYNC_COMMONSTATUS_ITEMNOTFOUND);
         }
         $mobj2 = new Mail_mimeDecode($origmail);
         // receive only body
         $body .= $this->getBody($mobj2->decode(array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8')));
         // unset mimedecoder & origmail - free memory
         unset($mobj2);
         unset($origmail);
     }
     // encode the body to base64 if it was sent originally in base64 by the pda
     // contrib - chunk base64 encoded body
     if ($body_base64 && !$sm->forwardflag) {
         $body = chunk_split(base64_encode($body));
     }
     // forward
     if ($sm->forwardflag && $parent) {
         $this->imap_reopenFolder($parent);
         // receive entire mail (header + body)
         $origmail = @imap_fetchheader($this->mbox, $forward, FT_UID) . @imap_body($this->mbox, $forward, FT_PEEK | FT_UID);
         if (!$origmail) {
             throw new StatusException(sprintf("BackendIMAP->SendMail(): Could not open message id '%s' in folder id '%s' to be forwarded: %s", $forward, $parent, imap_last_error()), SYNC_COMMONSTATUS_ITEMNOTFOUND);
         }
         if (!defined('IMAP_INLINE_FORWARD') || IMAP_INLINE_FORWARD === false) {
             // contrib - chunk base64 encoded body
             if ($body_base64) {
                 $body = chunk_split(base64_encode($body));
             }
             //use original boundary if it's set
             $boundary = $org_boundary ? $org_boundary : false;
             // build a new mime message, forward entire old mail as file
             list($aheader, $body) = $this->mail_attach("forwarded_message.eml", strlen($origmail), $origmail, $body, $forward_h_ct, $forward_h_cte, $boundary);
             // add boundary headers
             $headers .= "\n" . $aheader;
         } else {
             $mobj2 = new Mail_mimeDecode($origmail);
             $mess2 = $mobj2->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
             if (!$use_orgbody) {
                 $nbody = $body;
             } else {
                 $nbody = $repl_body;
             }
             $nbody .= "\r\n\r\n";
             $nbody .= "-----Original Message-----\r\n";
             if (isset($mess2->headers['from'])) {
                 $nbody .= "From: " . $mess2->headers['from'] . "\r\n";
             }
             if (isset($mess2->headers['to']) && strlen($mess2->headers['to']) > 0) {
                 $nbody .= "To: " . $mess2->headers['to'] . "\r\n";
             }
             if (isset($mess2->headers['cc']) && strlen($mess2->headers['cc']) > 0) {
                 $nbody .= "Cc: " . $mess2->headers['cc'] . "\r\n";
             }
             if (isset($mess2->headers['date'])) {
                 $nbody .= "Sent: " . $mess2->headers['date'] . "\r\n";
             }
             if (isset($mess2->headers['subject'])) {
                 $nbody .= "Subject: " . $mess2->headers['subject'] . "\r\n";
             }
             $nbody .= "\r\n";
             $nbody .= $this->getBody($mess2);
             if ($body_base64) {
                 // contrib - chunk base64 encoded body
                 $nbody = chunk_split(base64_encode($nbody));
                 if ($use_orgbody) {
                     // contrib - chunk base64 encoded body
                     $repl_body = chunk_split(base64_encode($repl_body));
                 }
             }
             if ($use_orgbody) {
                 ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): -------------------");
                 ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): old:\n'{$repl_body}'\nnew:\n'{$nbody}'\nund der body:\n'{$body}'");
                 //$body is quoted-printable encoded while $repl_body and $nbody are plain text,
                 //so we need to decode $body in order replace to take place
                 $body = str_replace($repl_body, $nbody, quoted_printable_decode($body));
             } else {
                 $body = $nbody;
             }
             if (isset($mess2->parts)) {
                 $attached = false;
                 if ($org_boundary) {
                     $att_boundary = $org_boundary;
                     // cut end boundary from body
                     $body = substr($body, 0, strrpos($body, "--{$att_boundary}--"));
                 } else {
                     $att_boundary = strtoupper(md5(uniqid(time())));
                     // add boundary headers
                     $headers .= "\n" . "Content-Type: multipart/mixed; boundary={$att_boundary}";
                     $multipartmixed = true;
                 }
                 foreach ($mess2->parts as $part) {
                     if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline")) {
                         if (isset($part->d_parameters['filename'])) {
                             $attname = $part->d_parameters['filename'];
                         } else {
                             if (isset($part->ctype_parameters['name'])) {
                                 $attname = $part->ctype_parameters['name'];
                             } else {
                                 if (isset($part->headers['content-description'])) {
                                     $attname = $part->headers['content-description'];
                                 } else {
                                     $attname = "unknown attachment";
                                 }
                             }
                         }
                         // ignore html content
                         if ($part->ctype_primary == "text" && $part->ctype_secondary == "html") {
                             continue;
                         }
                         //
                         if ($use_orgbody || $attached) {
                             $body .= $this->enc_attach_file($att_boundary, $attname, strlen($part->body), $part->body, $part->ctype_primary . "/" . $part->ctype_secondary);
                         } else {
                             $encmail = $body;
                             $attached = true;
                             $body = $this->enc_multipart($att_boundary, $body, $forward_h_ct, $forward_h_cte);
                             $body .= $this->enc_attach_file($att_boundary, $attname, strlen($part->body), $part->body, $part->ctype_primary . "/" . $part->ctype_secondary);
                         }
                     }
                 }
                 if ($multipartmixed && strpos(strtolower($mess2->headers['content-type']), "alternative") !== false) {
                     //this happens if a multipart/alternative message is forwarded
                     //then it's a multipart/mixed message which consists of:
                     //1. text/plain part which was written on the mobile
                     //2. multipart/alternative part which is the original message
                     $body = "This is a message with multiple parts in MIME format.\n--" . $att_boundary . "\nContent-Type: {$forward_h_ct}\nContent-Transfer-Encoding: {$forward_h_cte}\n\n" . ($body_base64 ? chunk_split(base64_encode($message->body)) : rtrim($message->body)) . "\n--" . $att_boundary . "\nContent-Type: {$mess2->headers['content-type']}\n\n" . @imap_body($this->mbox, $forward, FT_PEEK | FT_UID) . "\n\n";
                 }
                 $body .= "--{$att_boundary}--\n\n";
             }
             unset($mobj2);
         }
         // unset origmail - free memory
         unset($origmail);
     }
     // remove carriage-returns from body
     $body = str_replace("\r\n", "\n", $body);
     if (!$multipartmixed) {
         if (!empty($forward_h_ct)) {
             $headers .= "\nContent-Type: {$forward_h_ct}";
         }
         if (!empty($forward_h_cte)) {
             $headers .= "\nContent-Transfer-Encoding: {$forward_h_cte}";
         }
         //  if body was quoted-printable, convert it again
         if (isset($message->headers["content-transfer-encoding"]) && strtolower($message->headers["content-transfer-encoding"]) == "quoted-printable") {
             $body = quoted_printable_encode($body);
         }
     }
     // more debugging
     ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): parsed message: " . print_r($message, 1));
     ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): headers: {$headers}");
     /* BEGIN fmbiete's contribution r1528, ZP-320 */
     if (isset($message->headers["subject"])) {
         ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): subject: {$message->headers["subject"]}");
     } else {
         ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): subject: no subject set. Set to empty.");
         $message->headers["subject"] = "";
         // added by mku ZP-330
     }
     /* END fmbiete's contribution r1528, ZP-320 */
     ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): body: {$body}");
     if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) {
         // changed by mku ZP-330
         $send = @imap_mail($toaddr, $message->headers["subject"], $body, $headers, $ccaddr, $bccaddr);
     } else {
         if (!empty($ccaddr)) {
             $headers .= "\nCc: {$ccaddr}";
         }
         if (!empty($bccaddr)) {
             $headers .= "\nBcc: {$bccaddr}";
         }
         // changed by mku ZP-330
         $send = @mail($toaddr, $message->headers["subject"], $body, $headers, $envelopefrom);
     }
     // email sent?
     if (!$send) {
         throw new StatusException(sprintf("BackendIMAP->SendMail(): The email could not be sent. Last IMAP-error: %s", imap_last_error()), SYNC_COMMONSTATUS_MAILSUBMISSIONFAILED);
     }
     // add message to the sent folder
     // build complete headers
     $headers .= "\nTo: {$toaddr}";
     $headers .= "\nSubject: " . $message->headers["subject"];
     // changed by mku ZP-330
     if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) {
         if (!empty($ccaddr)) {
             $headers .= "\nCc: {$ccaddr}";
         }
         if (!empty($bccaddr)) {
             $headers .= "\nBcc: {$bccaddr}";
         }
     }
     ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): complete headers: {$headers}");
     $asf = false;
     if ($this->sentID) {
         $asf = $this->addSentMessage($this->sentID, $headers, $body);
     } else {
         if (IMAP_SENTFOLDER) {
             $asf = $this->addSentMessage(IMAP_SENTFOLDER, $headers, $body);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->SendMail(): Outgoing mail saved in configured 'Sent' folder '%s': %s", IMAP_SENTFOLDER, Utils::PrintAsString($asf)));
         } else {
             ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): No Sent mailbox set");
             if ($this->addSentMessage("INBOX.Sent", $headers, $body)) {
                 ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): Outgoing mail saved in 'INBOX.Sent'");
                 $asf = true;
             } else {
                 if ($this->addSentMessage("Sent", $headers, $body)) {
                     ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): Outgoing mail saved in 'Sent'");
                     $asf = true;
                 } else {
                     if ($this->addSentMessage("Sent Items", $headers, $body)) {
                         ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail():IMAP-SendMail: Outgoing mail saved in 'Sent Items'");
                         $asf = true;
                     }
                 }
             }
         }
     }
     if (!$asf) {
         ZLog::Write(LOGLEVEL_ERROR, "BackendIMAP->SendMail(): The email could not be saved to Sent Items folder. Check your configuration.");
     }
     return $send;
 }
Exemple #22
0
    }
    $body[1] = $part1;
    $body[2] = $part2;
    if ($filename != "") {
        $body[3] = $part3;
    }
    $message = imap_mail_compose($envelope, $body);
    list($msgheader, $msgbody) = split("\r\n\r\n", $message, 2);
    $data = trim($_POST[touser]);
    $datas = explode("*", $data);
    $mail_date = date("Y-m-d H:i:s");
    //获取时间
    $ip = getenv('REMOTE_ADDR');
    //获取IP地址
    while (list($name, $value) = each($datas)) {
        $sendes = imap_mail($value, $subject, $msgbody, $msgheader);
        include_once "conn/conn.php";
        $sql = "insert into tb_mail(mail_ip,mail_title,mail_formuser,mail_touser,mail_date)values('" . $ip . "','" . $subject . "','" . $_POST[fromuser] . "','" . $value . "','" . $mail_date . "')";
        $rs = new com("adodb.recordset");
        $rs->open($sql, $conn, 3, 1);
    }
    if ($sendes == true) {
        echo "<script>alert('邮件发送成功!');history.back();</script>";
    } else {
        echo "<script>alert('邮件发送失败!');history.back();</script>";
    }
}
?>
 

Exemple #23
0
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     debugLog("IMAP-SendMail: for: {$forward}   reply: {$reply}   parent: {$parent}  RFC822:  \n" . $rfc822);
     $mobj = new Mail_mimeDecode($rfc822);
     $message = $mobj->decode(array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
     $Mail_RFC822 = new Mail_RFC822();
     $toaddr = $ccaddr = $bccaddr = "";
     if (isset($message->headers["to"])) {
         $toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["to"]));
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["cc"]));
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["bcc"]));
     }
     // save some headers when forwarding mails (content type & transfer-encoding)
     $headers = "";
     $forward_h_ct = "";
     $forward_h_cte = "";
     $envelopefrom = "";
     $use_orgbody = false;
     // clean up the transmitted headers
     // remove default headers because we are using imap_mail
     $changedfrom = false;
     $returnPathSet = false;
     $body_base64 = false;
     $org_charset = "";
     $org_boundary = false;
     $multipartmixed = false;
     foreach ($message->headers as $k => $v) {
         if ($k == "subject" || $k == "to" || $k == "cc" || $k == "bcc") {
             continue;
         }
         if ($k == "content-type") {
             // if the message is a multipart message, then we should use the sent body
             if (preg_match("/multipart/i", $v)) {
                 $use_orgbody = true;
                 $org_boundary = $message->ctype_parameters["boundary"];
             }
             // save the original content-type header for the body part when forwarding
             if ($forward && !$use_orgbody) {
                 $forward_h_ct = $v;
                 continue;
             }
             // set charset always to utf-8
             $org_charset = $v;
             $v = preg_replace("/charset=([A-Za-z0-9-\"']+)/", "charset=\"utf-8\"", $v);
         }
         if ($k == "content-transfer-encoding") {
             // if the content was base64 encoded, encode the body again when sending
             if (trim($v) == "base64") {
                 $body_base64 = true;
             }
             // save the original encoding header for the body part when forwarding
             if ($forward) {
                 $forward_h_cte = $v;
                 continue;
             }
         }
         // check if "from"-header is set, do nothing if it's set
         // else set it to IMAP_DEFAULTFROM
         if ($k == "from") {
             if (trim($v)) {
                 $changedfrom = true;
                 $envelopefrom = "-f{$v}";
             } elseif (!trim($v) && IMAP_DEFAULTFROM) {
                 $changedfrom = true;
                 if (IMAP_DEFAULTFROM == 'username') {
                     $v = $this->_username;
                 } else {
                     if (IMAP_DEFAULTFROM == 'domain') {
                         $v = $this->_domain;
                     } else {
                         $v = $this->_username . IMAP_DEFAULTFROM;
                     }
                 }
                 $envelopefrom = "-f{$v}";
             }
         }
         // check if "Return-Path"-header is set
         if ($k == "return-path") {
             $returnPathSet = true;
             if (!trim($v) && IMAP_DEFAULTFROM) {
                 if (IMAP_DEFAULTFROM == 'username') {
                     $v = $this->_username;
                 } else {
                     if (IMAP_DEFAULTFROM == 'domain') {
                         $v = $this->_domain;
                     } else {
                         $v = $this->_username . IMAP_DEFAULTFROM;
                     }
                 }
             }
         }
         // all other headers stay
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= ucfirst($k) . ": " . $v;
     }
     // set "From" header if not set on the device
     if (IMAP_DEFAULTFROM && !$changedfrom) {
         if (IMAP_DEFAULTFROM == 'username') {
             $v = $this->_username;
         } else {
             if (IMAP_DEFAULTFROM == 'domain') {
                 $v = $this->_domain;
             } else {
                 $v = $this->_username . IMAP_DEFAULTFROM;
             }
         }
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'From: ' . $v;
         $envelopefrom = "-f{$v}";
     }
     // set "Return-Path" header if not set on the device
     if (IMAP_DEFAULTFROM && !$returnPathSet) {
         if (IMAP_DEFAULTFROM == 'username') {
             $v = $this->_username;
         } else {
             if (IMAP_DEFAULTFROM == 'domain') {
                 $v = $this->_domain;
             } else {
                 $v = $this->_username . IMAP_DEFAULTFROM;
             }
         }
         if ($headers) {
             $headers .= "\n";
         }
         $headers .= 'Return-Path: ' . $v;
     }
     // if this is a multipart message with a boundary, we must use the original body
     if ($use_orgbody) {
         list(, $body) = $mobj->_splitBodyHeader($rfc822);
         $repl_body = $this->getBody($message);
     } else {
         $body = $this->getBody($message);
     }
     // reply
     if ($reply && $parent) {
         $this->imap_reopenFolder($parent);
         // receive entire mail (header + body) to decode body correctly
         $origmail = @imap_fetchheader($this->_mbox, $reply, FT_UID) . @imap_body($this->_mbox, $reply, FT_PEEK | FT_UID);
         $mobj2 = new Mail_mimeDecode($origmail);
         // receive only body
         $body .= $this->getBody($mobj2->decode(array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8')));
         // unset mimedecoder & origmail - free memory
         unset($mobj2);
         unset($origmail);
     }
     // encode the body to base64 if it was sent originally in base64 by the pda
     // contrib - chunk base64 encoded body
     if ($body_base64 && !$forward) {
         $body = chunk_split(base64_encode($body));
     }
     // forward
     if ($forward && $parent) {
         $this->imap_reopenFolder($parent);
         // receive entire mail (header + body)
         $origmail = @imap_fetchheader($this->_mbox, $forward, FT_UID) . @imap_body($this->_mbox, $forward, FT_PEEK | FT_UID);
         if (!defined('IMAP_INLINE_FORWARD') || IMAP_INLINE_FORWARD === false) {
             // contrib - chunk base64 encoded body
             if ($body_base64) {
                 $body = chunk_split(base64_encode($body));
             }
             //use original boundary if it's set
             $boundary = $org_boundary ? $org_boundary : false;
             // build a new mime message, forward entire old mail as file
             list($aheader, $body) = $this->mail_attach("forwarded_message.eml", strlen($origmail), $origmail, $body, $forward_h_ct, $forward_h_cte, $boundary);
             // add boundary headers
             $headers .= "\n" . $aheader;
         } else {
             $mobj2 = new Mail_mimeDecode($origmail);
             $mess2 = $mobj2->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
             if (!$use_orgbody) {
                 $nbody = $body;
             } else {
                 $nbody = $repl_body;
             }
             $nbody .= "\r\n\r\n";
             $nbody .= "-----Original Message-----\r\n";
             if (isset($mess2->headers['from'])) {
                 $nbody .= "From: " . $mess2->headers['from'] . "\r\n";
             }
             if (isset($mess2->headers['to']) && strlen($mess2->headers['to']) > 0) {
                 $nbody .= "To: " . $mess2->headers['to'] . "\r\n";
             }
             if (isset($mess2->headers['cc']) && strlen($mess2->headers['cc']) > 0) {
                 $nbody .= "Cc: " . $mess2->headers['cc'] . "\r\n";
             }
             if (isset($mess2->headers['date'])) {
                 $nbody .= "Sent: " . $mess2->headers['date'] . "\r\n";
             }
             if (isset($mess2->headers['subject'])) {
                 $nbody .= "Subject: " . $mess2->headers['subject'] . "\r\n";
             }
             $nbody .= "\r\n";
             $nbody .= $this->getBody($mess2);
             if ($body_base64) {
                 // contrib - chunk base64 encoded body
                 $nbody = chunk_split(base64_encode($nbody));
                 if ($use_orgbody) {
                     // contrib - chunk base64 encoded body
                     $repl_body = chunk_split(base64_encode($repl_body));
                 }
             }
             if ($use_orgbody) {
                 debugLog("-------------------");
                 debugLog("old:\n'{$repl_body}'\nnew:\n'{$nbody}'\nund der body:\n'{$body}'");
                 //$body is quoted-printable encoded while $repl_body and $nbody are plain text,
                 //so we need to decode $body in order replace to take place
                 $body = str_replace($repl_body, $nbody, quoted_printable_decode($body));
             } else {
                 $body = $nbody;
             }
             if (isset($mess2->parts)) {
                 $attached = false;
                 if ($org_boundary) {
                     $att_boundary = $org_boundary;
                     // cut end boundary from body
                     $body = substr($body, 0, strrpos($body, "--{$att_boundary}--"));
                 } else {
                     $att_boundary = strtoupper(md5(uniqid(time())));
                     // add boundary headers
                     $headers .= "\n" . "Content-Type: multipart/mixed; boundary={$att_boundary}";
                     $multipartmixed = true;
                 }
                 foreach ($mess2->parts as $part) {
                     if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline")) {
                         if (isset($part->d_parameters['filename'])) {
                             $attname = $part->d_parameters['filename'];
                         } else {
                             if (isset($part->ctype_parameters['name'])) {
                                 $attname = $part->ctype_parameters['name'];
                             } else {
                                 if (isset($part->headers['content-description'])) {
                                     $attname = $part->headers['content-description'];
                                 } else {
                                     $attname = "unknown attachment";
                                 }
                             }
                         }
                         // ignore html content
                         if ($part->ctype_primary == "text" && $part->ctype_secondary == "html") {
                             continue;
                         }
                         //
                         if ($use_orgbody || $attached) {
                             $body .= $this->enc_attach_file($att_boundary, $attname, strlen($part->body), $part->body, $part->ctype_primary . "/" . $part->ctype_secondary);
                         } else {
                             $encmail = $body;
                             $attached = true;
                             $body = $this->enc_multipart($att_boundary, $body, $forward_h_ct, $forward_h_cte);
                             $body .= $this->enc_attach_file($att_boundary, $attname, strlen($part->body), $part->body, $part->ctype_primary . "/" . $part->ctype_secondary);
                         }
                     }
                 }
                 if ($multipartmixed && strpos(strtolower($mess2->headers['content-type']), "alternative") !== false) {
                     //this happens if a multipart/alternative message is forwarded
                     //then it's a multipart/mixed message which consists of:
                     //1. text/plain part which was written on the mobile
                     //2. multipart/alternative part which is the original message
                     $body = "This is a message with multiple parts in MIME format.\n--" . $att_boundary . "\nContent-Type: {$forward_h_ct}\nContent-Transfer-Encoding: {$forward_h_cte}\n\n" . ($body_base64 ? chunk_split(base64_encode($message->body)) : rtrim($message->body)) . "\n--" . $att_boundary . "\nContent-Type: {$mess2->headers['content-type']}\n\n" . @imap_body($this->_mbox, $forward, FT_PEEK | FT_UID) . "\n\n";
                 }
                 $body .= "--{$att_boundary}--\n\n";
             }
             unset($mobj2);
         }
         // unset origmail - free memory
         unset($origmail);
     }
     // remove carriage-returns from body
     $body = str_replace("\r\n", "\n", $body);
     if (!$multipartmixed) {
         if (!empty($forward_h_ct)) {
             $headers .= "\nContent-Type: {$forward_h_ct}";
         }
         if (!empty($forward_h_cte)) {
             $headers .= "\nContent-Transfer-Encoding: {$forward_h_cte}";
         }
         //if body was quoted-printable, convert it again
         if (isset($message->headers["content-transfer-encoding"]) && strtolower($message->headers["content-transfer-encoding"]) == "quoted-printable") {
             $body = quoted_printable_encode($body);
         }
     }
     //advanced debugging
     //debugLog("IMAP-SendMail: parsed message: ". print_r($message,1));
     //debugLog("IMAP-SendMail: headers: $headers");
     //debugLog("IMAP-SendMail: subject: {$message->headers["subject"]}");
     //debugLog("IMAP-SendMail: body: $body");
     if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) {
         $send = @imap_mail($toaddr, $message->headers["subject"], $body, $headers, $ccaddr, $bccaddr);
     } else {
         if (!empty($ccaddr)) {
             $headers .= "\nCc: {$ccaddr}";
         }
         if (!empty($bccaddr)) {
             $headers .= "\nBcc: {$bccaddr}";
         }
         $send = @mail($toaddr, $message->headers["subject"], $body, $headers, $envelopefrom);
     }
     // email sent?
     if (!$send) {
         debugLog("The email could not be sent. Last-IMAP-error: " . imap_last_error());
     }
     // add message to the sent folder
     // build complete headers
     $headers .= "\nTo: {$toaddr}";
     $headers .= "\nSubject: " . $message->headers["subject"];
     if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) {
         if (!empty($ccaddr)) {
             $headers .= "\nCc: {$ccaddr}";
         }
         if (!empty($bccaddr)) {
             $headers .= "\nBcc: {$bccaddr}";
         }
     }
     //debugLog("IMAP-SendMail: complete headers: $headers");
     $asf = false;
     if ($this->_sentID) {
         $asf = $this->addSentMessage($this->_sentID, $headers, $body);
     } else {
         if (IMAP_SENTFOLDER) {
             $asf = $this->addSentMessage(IMAP_SENTFOLDER, $headers, $body);
             debugLog("IMAP-SendMail: Outgoing mail saved in configured 'Sent' folder '" . IMAP_SENTFOLDER . "': " . ($asf ? "success" : "failed"));
         } else {
             debugLog("IMAP-SendMail: No Sent mailbox set");
             if ($this->addSentMessage("INBOX.Sent", $headers, $body)) {
                 debugLog("IMAP-SendMail: Outgoing mail saved in 'INBOX.Sent'");
                 $asf = true;
             } else {
                 if ($this->addSentMessage("Sent", $headers, $body)) {
                     debugLog("IMAP-SendMail: Outgoing mail saved in 'Sent'");
                     $asf = true;
                 } else {
                     if ($this->addSentMessage("Sent Items", $headers, $body)) {
                         debugLog("IMAP-SendMail: Outgoing mail saved in 'Sent Items'");
                         $asf = true;
                     }
                 }
             }
         }
     }
     // unset mimedecoder - free memory
     unset($mobj);
     return $send && $asf;
 }
Exemple #24
0
        $tweet = array();
        $screen_name = array();
        $message_number_list = array();
        //if there is a message in your inbox, get the screen name and tweet
        while ($message_number_get <= $message_count) {
            //read that mail recently arrived
            $tweet[] = imap_fetchbody($imap, $message_number_get, 1);
            $header = imap_headerinfo($imap, $message_number_get);
            $screen_name[] = $header->subject;
            $message_number_list[] = $message_number_get;
            $message_number_get++;
        }
        //post the tweet list and send email responses
        foreach ($message_number_list as $message_number_post) {
            tw_post($screen_name[$message_number_post], $tweet[$message_number_post]);
            imap_mail('*****@*****.**', 'Your message has been posted to Twitter', 'Your message has been posted to Twitter.');
        }
        //mark the posted emails for deletion
        foreach ($message_number_list as $message_number_del) {
            imap_delete($imap, $message_number_del);
        }
        //delete (expunge) all the marked messages
        imap_expunge($imap);
    }
    //close the stream
    imap_close($imap);
    //sleep for 10 min and continue;
    sleep(10 * 60);
}
//...............................................................................
function tw_post($screen_name, $tweet)
Exemple #25
-1
 function imap_send_mail($to, $subject, $message, $additional_headers = NULL, $cc = NULL, $bcc = NULL, $rpath = NULL)
 {
     if (@imap_mail($to, $subject, $message, $additional_headers = NULL, $cc = NULL, $bcc = NULL, $rpath = NULL)) {
         return TRUE;
     } else {
         return FALSE;
     }
 }