本文整理汇总了PHP中Mail_mimePart::addSubpart方法的典型用法代码示例。如果您正苦于以下问题:PHP Mail_mimePart::addSubpart方法的具体用法?PHP Mail_mimePart::addSubpart怎么用?PHP Mail_mimePart::addSubpart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mail_mimePart
的用法示例。
在下文中一共展示了Mail_mimePart::addSubpart方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encodeMimeMultipart
/**
* Given array of MIME parts in raw string, this function converts them into MIME
* representation.
*
* @param array $bodyPartContents The MIME body parts.
*
* @return array Returns array with two elements 'headers' and 'body' which
* represents the MIME message.
*/
public function encodeMimeMultipart($bodyPartContents)
{
$count = count($bodyPartContents);
$mimeType = Resources::MULTIPART_MIXED_TYPE;
$batchGuid = strtolower(trim(com_create_guid(), '{}'));
$batchId = sprintf('batch_%s', $batchGuid);
$contentType1 = array('content_type' => "{$mimeType}");
$changeSetGuid = strtolower(trim(com_create_guid(), '{}'));
$changeSetId = sprintf('changeset_%s', $changeSetGuid);
$contentType2 = array('content_type' => "{$mimeType}; boundary={$changeSetId}");
$options = array('encoding' => 'binary', 'content_type' => Resources::HTTP_TYPE);
// Create changeset MIME part
$changeSet = new \Mail_mimePart();
for ($i = 0; $i < $count; $i++) {
$changeSet->addSubpart($bodyPartContents[$i], $options);
}
// Encode the changeset MIME part
$changeSetEncoded = $changeSet->encode($changeSetId);
// Create the batch MIME part
$batch = new \Mail_mimePart(Resources::EMPTY_STRING, $contentType1);
// Add changeset encoded to batch MIME part
$batch->addSubpart($changeSetEncoded['body'], $contentType2);
// Encode batch MIME part
$batchEncoded = $batch->encode($batchId);
return $batchEncoded;
}
示例2: get
/**
* Builds the multipart message.
*
* @param array $params Build parameters that change the way the email
* is built. Should be associative. See $_build_params.
* @param resource $filename Output file where to save the message instead of
* returning it
* @param boolean $skip_head True if you want to return/save only the message
* without headers
*
* @return mixed The MIME message content string, null or PEAR error object
*/
public function get($params = null, $filename = null, $skip_head = false)
{
if (isset($params)) {
while (list($key, $value) = each($params)) {
$this->build_params[$key] = $value;
}
}
$this->checkParams();
if ($this->type == self::PGP_SIGNED) {
$params = array('preamble' => "This is an OpenPGP/MIME signed message (RFC 4880 and 3156)", 'content_type' => "multipart/signed; micalg=pgp-sha1; protocol=\"application/pgp-signature\"", 'eol' => $this->build_params['eol']);
$message = new Mail_mimePart('', $params);
if (!empty($this->body)) {
$headers = $this->message->headers();
$params = array('content_type' => $headers['Content-Type']);
if ($headers['Content-Transfer-Encoding']) {
$params['encoding'] = $headers['Content-Transfer-Encoding'];
}
$message->addSubpart($this->body, $params);
}
if (!empty($this->signature)) {
$message->addSubpart($this->signature, array('filename' => 'signature.asc', 'content_type' => 'application/pgp-signature', 'disposition' => 'attachment', 'description' => 'OpenPGP digital signature'));
}
} else {
if ($this->type == self::PGP_ENCRYPTED) {
$params = array('preamble' => "This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)", 'content_type' => "multipart/encrypted; protocol=\"application/pgp-encrypted\"", 'eol' => $this->build_params['eol']);
$message = new Mail_mimePart('', $params);
$message->addSubpart('Version: 1', array('content_type' => 'application/pgp-encrypted', 'description' => 'PGP/MIME version identification'));
$message->addSubpart($this->encrypted, array('content_type' => 'application/octet-stream', 'description' => 'PGP/MIME encrypted message', 'disposition' => 'inline', 'filename' => 'encrypted.asc'));
}
}
// Use saved boundary
if (!empty($this->build_params['boundary'])) {
$boundary = $this->build_params['boundary'];
} else {
$boundary = null;
}
// Write output to file
if ($filename) {
// Append mimePart message headers and body into file
$headers = $message->encodeToFile($filename, $boundary, $skip_head);
if ($this->isError($headers)) {
return $headers;
}
$this->headers = array_merge($this->headers, $headers);
return null;
} else {
$output = $message->encode($boundary, $skip_head);
if ($this->isError($output)) {
return $output;
}
$this->headers = array_merge($this->headers, $output['headers']);
return $output['body'];
}
}
示例3: getHTTPBody
/**
* gets the HTTP body for the current response.
*
* @param string $soapmsg The SOAP payload
* @return string The HTTP body, which includes the SOAP payload
* @access private
*/
function getHTTPBody($soapmsg)
{
if (count($this->responseAttachments) > 0) {
$params['content_type'] = 'multipart/related; type="text/xml"';
$mimeMessage = new Mail_mimePart('', $params);
unset($params);
$params['content_type'] = 'text/xml';
$params['encoding'] = '8bit';
$params['charset'] = $this->soap_defencoding;
$mimeMessage->addSubpart($soapmsg, $params);
foreach ($this->responseAttachments as $att) {
unset($params);
$params['content_type'] = $att['contenttype'];
$params['encoding'] = 'base64';
$params['disposition'] = 'attachment';
$params['dfilename'] = $att['filename'];
$params['cid'] = $att['cid'];
if ($att['data'] == '' && $att['filename'] != '') {
if ($fd = fopen($att['filename'], 'rb')) {
$data = fread($fd, filesize($att['filename']));
fclose($fd);
} else {
$data = '';
}
$mimeMessage->addSubpart($data, $params);
} else {
$mimeMessage->addSubpart($att['data'], $params);
}
}
$output = $mimeMessage->encode();
$mimeHeaders = $output['headers'];
foreach ($mimeHeaders as $k => $v) {
$this->debug("MIME header {$k}: {$v}");
if (strtolower($k) == 'content-type') {
// PHP header() seems to strip leading whitespace starting
// the second line, so force everything to one line
$this->mimeContentType = str_replace("\r\n", " ", $v);
}
}
return $output['body'];
}
return parent::getHTTPBody($soapmsg);
}
示例4: encode
/**
* Encode contexts
*
* @return none
*/
public function encode()
{
$mimeType = Resources::MULTIPART_MIXED_TYPE;
$batchGuid = Utilities::getGuid();
$batchId = sprintf('batch_%s', $batchGuid);
$contentType1 = array('content_type' => "{$mimeType}");
$changeSetGuid = Utilities::getGuid();
$changeSetId = sprintf('changeset_%s', $changeSetGuid);
$contentType2 = array('content_type' => "{$mimeType}; boundary={$changeSetId}");
$options = array('encoding' => 'binary', 'content_type' => Resources::HTTP_TYPE);
// Create changeset MIME part
$changeSet = new \Mail_mimePart();
$i = 1;
foreach ($this->_contexts as $context) {
$context->addHeader(Resources::CONTENT_ID, $i);
$changeSet->addSubpart((string) $context, $options);
$i++;
}
// Encode the changeset MIME part
$changeSetEncoded = $changeSet->encode($changeSetId);
// Create the batch MIME part
$batch = new \Mail_mimePart(Resources::EMPTY_STRING, $contentType1);
// Add changeset encoded to batch MIME part
$batch->addSubpart($changeSetEncoded['body'], $contentType2);
// Encode batch MIME part
$batchEncoded = $batch->encode($batchId);
$this->_headers = $batchEncoded['headers'];
$this->_body = $batchEncoded['body'];
}