예제 #1
0
 public function sendMMS($senderAddress, $addressList, $message, $attachments, $senderName, $clientCorrelator, $notifyURL, $callbackData)
 {
     $sendMMSResponse = null;
     if ($senderAddress && $addressList && ($message || $attachments)) {
         if (!is_null($this->endpoint) && property_exists($this->endpoint, 'SendSMS')) {
             $url = $this->endpoint->getSendMMSEndpoint();
         } else {
             $url = 'http://localhost:8080/oneapiserver/SendMMSService/1/messaging/outbound/{senderAddress}/requests';
         }
         $url = str_replace('{senderAddress}', urlencode($senderAddress), $url);
         $formParameters = new FormParameters();
         $formParameters->put("senderAddress", $senderAddress);
         for ($i = 0; $i < count($addressList); $i++) {
             $formParameters->put("address", $addressList[$i]);
         }
         $formParameters->put("message", $message);
         $formParameters->put("clientCorrelator", $clientCorrelator);
         $formParameters->put("notifyURL", $notifyURL);
         $formParameters->put("senderName", $senderName);
         $formParameters->put("callbackData", $callbackData);
         $params = array();
         $params['content_type'] = 'multipart/mixed';
         $requestBody = new Mail_mimePart('', $params);
         $params['content_type'] = 'application/x-www-form-urlencoded';
         //$params['encoding']     = '8bit';
         $params['disposition'] = 'form-data; name="root-fields"';
         $text = $requestBody->addSubPart($formParameters->encodeParameters(), $params);
         error_log('Processing attachments');
         if ($attachments && is_array($attachments) && count($attachments) > 0) {
             for ($i = 0; $i < count($attachments); $i++) {
                 error_log('Processing file ' . $i);
                 $file = $attachments[$i];
                 if ($file && is_array($file) && isset($file['error']) && $file['error'] == UPLOAD_ERR_OK) {
                     error_log('Have attachment name=' . $file['name'] . ' type=' . $file['type'] . ' size=' . $file['size']);
                     $params['content_type'] = $file['type'];
                     $params['encoding'] = 'base64';
                     $params['disposition'] = 'form-data; name="' . $file['name'] . '"';
                     $contents = file_get_contents($file['tmp_name']);
                     $attach =& $requestBody->addSubPart($contents, $params);
                 }
             }
         }
         $content = $requestBody->encode();
         $contentType = $content['headers']['Content-Type'];
         $data = $content['body'];
         error_log('Generated...\\n' . print_r($content, true));
         $request = new JSONRequest($url, $this->username, $this->password, 'POST', null, $contentType, $data);
         $response = $request->execute();
         if ($response->getResponseBody()) {
             $jsondata = json_decode($response->getResponseBody());
         }
         error_log("MMSSend::sendMMS response=" . print_r($response, true));
         error_log("MMSSend::sendMMS jsondata=" . print_r($jsondata, true));
         $responseInfo = $response->getResponseInfo();
         $location = $response->getLocation();
         $sendMMSResponse = new MMSSendResponse($responseInfo["http_code"], $responseInfo["content_type"], $location, $jsondata);
         error_log("MMSSend::sendMMS sendMMSResponse=" . print_r($sendMMSResponse, true));
     }
     return $sendMMSResponse;
 }
 public function send()
 {
     $to = $this->getSetting('to', '');
     $from = $this->getSetting('from', '');
     $subject = $this->getSetting('subject', '');
     $encoding = $this->getSetting('encoding', '');
     $body = $this->getSetting('content', '');
     $error = '';
     $crlf = '';
     $params = array();
     $params['host'] = $this->getSetting('server', '');
     $params['auth'] = $this->getSetting('auth', true);
     $params['username'] = $this->getSetting('user', '');
     $params['password'] = $this->getSetting('password', '');
     $params['port'] = $this->getSetting('port', '587');
     $headers = array();
     $headers['To'] = 'To: ' . $to;
     $headers['From'] = 'From: ' . $from;
     $headers['Subject'] = $subject;
     $htmlparams = array('charset' => 'utf-8', 'content_type' => 'text/html', 'encoding' => 'quoted/printable');
     $email = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     $htmlmime = $email->addSubPart($this->getTemplate(), $htmlparams);
     $final = $email->encode();
     $final['headers'] = array_merge($final['headers'], $headers);
     $smtp = Mail::factory('smtp', $params);
     $mail = $smtp->send($to, $final['headers'], $final['body']);
     if (PEAR::isError($mail)) {
         $error = $mail->getMessage();
     }
     return $error;
 }
예제 #3
0
파일: CntMail.php 프로젝트: makinuk/Qcore
 public function sendTextMail(PrmPerson $to, $Header, $Body, PrmPerson $ReplyTo = null)
 {
     $headers['To'] = $to->getForMailUser();
     $headers['From'] = $this->_From;
     $headers['Return-Path'] = $this->_From;
     if ($ReplyTo != null) {
         $headers['Reply-To'] = $ReplyTo->getForMailUser();
     }
     $headers['Subject'] = $Header;
     $headers['Errors-To'] = '<<a href="mailto:errors@example.com">errors@example.com</a>>';
     $headers['MIME-Version'] = '1.0';
     $textparams = array('charset' => 'utf-8', 'content_type' => 'text/plain', 'encoding' => 'quoted/printable');
     $email = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     $textmime = $email->addSubPart($Body, $textparams);
     $final = $email->encode();
     $final['headers'] = array_merge($final['headers'], $headers);
     $smtp_params = array();
     $smtp_params['host'] = $this->_Host;
     $smtp_params['port'] = $this->_Port;
     $smtp_params['auth'] = true;
     $smtp_params['username'] = $this->_UserName;
     $smtp_params['password'] = $this->_Password;
     $smtp_params['debug'] = false;
     //$smtp_params['persist'] = TRUE;
     $mail =& Mail::factory('smtp', $smtp_params);
     $status = $mail->send($to->getForMailUser(), $final['headers'], $final['body']);
     if (PEAR::isError($status)) {
         print $status->getMessage();
         exit;
         return false;
     } else {
         return true;
     }
 }
예제 #4
0
파일: Base.php 프로젝트: rolwi/koala
 function _makeMimeMessage($xml, $encoding = SOAP_DEFAULT_ENCODING)
 {
     if (!@(include_once 'Mail/mimePart.php')) {
         return $this->_raiseSoapFault('MIME messages are unsupported, the Mail_Mime package is not installed');
     }
     // Encode any attachments.  See http://www.w3.org/TR/SOAP-attachments
     // Now we have to mime encode the message.
     $params = array('content_type' => 'multipart/related; type="text/xml"');
     $msg = new Mail_mimePart('', $params);
     // Add the xml part.
     $params['content_type'] = 'text/xml';
     $params['charset'] = $encoding;
     $params['encoding'] = 'base64';
     $msg->addSubPart($xml, $params);
     // Add the attachements
     for ($i = 0, $c = count($this->_attachments); $i < $c; ++$i) {
         $msg->addSubPart($this->_attachments[$i]['body'], $this->_attachments[$i]);
     }
     return $msg->encode();
 }
 protected function eF_mail_multipart($sender, $recipient, $subject, $textbody, $calendarbody, $onlyText = false, $bcc = false)
 {
     $hdrs = array('From' => $sender, 'Subject' => $subject, 'Date' => date("r"));
     if ($bcc) {
         //$hdrs['To'] = '';
     }
     $params = array("text_charset" => "UTF-8", "html_charset" => "UTF-8", "head_charset" => "UTF-8", "head_encoding" => "base64");
     $textparams = array('charset' => 'utf-8', 'content_type' => 'text/plain', 'encoding' => 'base64');
     $calendarparams = array('charset' => 'utf-8', 'content_type' => 'text/calendar;method=REQUEST', 'encoding' => 'base64');
     $email = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     $textmime = $email->addSubPart($textbody, $textparams);
     $htmlmime = $email->addSubPart($calendarbody, $calendarparams);
     $final = $email->encode();
     $final['headers'] = array_merge($final['headers'], $hdrs);
     $smtp = Mail::factory('smtp', array('auth' => $GLOBALS['configuration']['smtp_auth'] ? true : false, 'host' => $GLOBALS['configuration']['smtp_host'], 'password' => $GLOBALS['configuration']['smtp_pass'], 'port' => $GLOBALS['configuration']['smtp_port'], 'username' => $GLOBALS['configuration']['smtp_user'], 'timeout' => $GLOBALS['configuration']['smtp_timeout'], 'localhost' => $_SERVER["HTTP_HOST"]));
     $result = $smtp->send($recipient, $final['headers'], $final['body']);
     return $result;
 }
예제 #6
0
 function &_makeMimeMessage(&$xml, $encoding = SOAP_DEFAULT_ENCODING)
 {
     global $SOAP_options;
     if (!isset($SOAP_options['Mime'])) {
         return $this->_raiseSoapFault('Mime is not installed');
     }
     // encode any attachments
     // see http://www.w3.org/TR/SOAP-attachments
     // now we have to mime encode the message
     $params = array('content_type' => 'multipart/related; type=text/xml');
     $msg = new Mail_mimePart('', $params);
     // add the xml part
     $params['content_type'] = 'text/xml';
     $params['charset'] = $encoding;
     $params['encoding'] = 'base64';
     $msg->addSubPart($xml, $params);
     // add the attachements
     $c = count($this->__attachments);
     for ($i = 0; $i < $c; $i++) {
         $attachment =& $this->__attachments[$i];
         $msg->addSubPart($attachment['body'], $attachment);
     }
     return $msg->encode();
 }
예제 #7
0
 /**
  * Add text parts to a mimepart object
  *
  * @param Mail_mimePart $email reference to the object
  * @param Mail_mimeDecode $message reference to the message
  *
  * @access private
  * @return void
  */
 private function addTextPartsMessage(&$email, &$message)
 {
     $htmlBody = $plainBody = '';
     Mail_mimeDecode::getBodyRecursive($message, "html", $htmlBody);
     Mail_mimeDecode::getBodyRecursive($message, "plain", $plainBody);
     $altEmail = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     if (strlen($htmlBody) > 0) {
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->addTextPartsMessage(): The message has HTML body"));
         $altEmail->addSubPart($htmlBody, array('content_type' => 'text/html; charset=utf-8', 'encoding' => 'base64'));
     }
     if (strlen($plainBody) > 0) {
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->addTextPartsMessage(): The message has PLAIN body"));
         $altEmail->addSubPart($plainBody, array('content_type' => 'text/plain; charset=utf-8', 'encoding' => 'base64'));
     }
     $boundary = '=_' . md5(rand() . microtime());
     $altEmail = $altEmail->encode($boundary);
     $email->addSubPart($altEmail['body'], array('content_type' => 'multipart/alternative;' . "\n" . ' boundary="' . $boundary . '"'));
     unset($altEmail);
     unset($htmlBody);
     unset($plainBody);
 }
예제 #8
0
 /**
  * Add text parts to a mimepart object
  *
  * @param Mail_mimePart $email reference to the object
  * @param Mail_mimeDecode $message reference to the message
  *
  * @access private
  * @return void
  */
 private function addTextPartsMessage(&$email, &$message)
 {
     $altEmail = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));
     foreach (array("plain", "html", "calendar") as $type) {
         $body = '';
         Mail_mimeDecode::getBodyRecursive($message, $type, $body);
         if (strlen($body) > 0) {
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->addTextPartsMessage(): The message has %s body", $type));
             $altEmail->addSubPart($body, array('content_type' => sprintf("text/%s; charset=utf-8", $type), 'encoding' => 'base64'));
         }
     }
     unset($body);
     $boundary = '=_' . md5(rand() . microtime());
     $altEmail = $altEmail->encode($boundary);
     $email->addSubPart($altEmail['body'], array('content_type' => 'multipart/alternative;' . "\n" . ' boundary="' . $boundary . '"'));
     unset($altEmail);
 }
예제 #9
0
/**
 * Add a subpart to a mimepart object.
 *
 * @param Mail_mimePart $email reference to the object
 * @param object $part message part
 *
 * @access private
 * @return void
 */
function add_sub_part(&$email, $part)
{
    //http://tools.ietf.org/html/rfc4021
    $new_part = null;
    $params = array();
    $params['content_type'] = '';
    if (isset($part) && isset($email)) {
        if (isset($part->ctype_primary)) {
            $params['content_type'] = $part->ctype_primary;
        }
        if (isset($part->ctype_secondary)) {
            $params['content_type'] .= '/' . $part->ctype_secondary;
        }
        if (isset($part->ctype_parameters)) {
            foreach ($part->ctype_parameters as $k => $v) {
                if (strcasecmp($k, 'boundary') != 0) {
                    $params['content_type'] .= '; ' . $k . '=' . $v;
                }
            }
        }
        if (isset($part->disposition)) {
            $params['disposition'] = $part->disposition;
        }
        //FIXME: dfilename => filename
        if (isset($part->d_parameters)) {
            foreach ($part->d_parameters as $k => $v) {
                $params[$k] = $v;
            }
        }
        foreach ($part->headers as $k => $v) {
            switch ($k) {
                case "content-description":
                    $params['description'] = $v;
                    break;
                case "content-type":
                case "content-disposition":
                case "content-transfer-encoding":
                    // Do nothing, we already did
                    break;
                case "content-id":
                    $params['cid'] = str_replace('<', '', str_replace('>', '', $v));
                    break;
                default:
                    $params[$k] = $v;
                    break;
            }
        }
        // If not exist body, the part will be multipart/alternative, so we don't add encoding
        if (!isset($params['encoding']) && isset($part->body)) {
            $params['encoding'] = 'base64';
        }
        // We could not have body; recursive messages
        $new_part = $email->addSubPart(isset($part->body) ? $part->body : "", $params);
        unset($params);
    }
    // return the new part
    return $new_part;
}