本文整理汇总了PHP中ezcMailTools类的典型用法代码示例。如果您正苦于以下问题:PHP ezcMailTools类的具体用法?PHP ezcMailTools怎么用?PHP ezcMailTools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ezcMailTools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendMail
function sendMail(ezcMail $mail)
{
$separator = "/";
$mail->appendExcludeHeaders(array('to', 'subject'));
$headers = rtrim($mail->generateHeaders());
// rtrim removes the linebreak at the end, mail doesn't want it.
if (count($mail->to) + count($mail->cc) + count($mail->bcc) < 1) {
throw new ezcMailTransportException('No recipient addresses found in message header.');
}
$additionalParameters = "";
if (isset($mail->returnPath)) {
$additionalParameters = "-f{$mail->returnPath->email}";
}
$sys = eZSys::instance();
$fname = time() . '-' . rand() . '.mail';
$qdir = eZSys::siteDir() . eZSys::varDirectory() . $separator . 'mailq';
$data = $headers . ezcMailTools::lineBreak();
$data .= ezcMailTools::lineBreak();
$data .= $mail->generateBody();
$data = preg_replace('/(\\r\\n|\\r|\\n)/', "\r\n", $data);
$success = eZFile::create($fname, $qdir, $data);
if ($success === false) {
throw new ezcMailTransportException('The email could not be sent by sendmail');
}
}
示例2: send
public static function send($to, $subject, $body, $options = array())
{
$siteINI = eZINI::instance('site.ini');
$i18nINI = eZINI::instance('i18n.ini');
$transport = $siteINI->variable('MailSettings', 'Transport');
$charset = $i18nINI->variable('CharacterSettings', 'Charset');
$emailSender = $siteINI->variable('MailSettings', 'EmailSender');
if (!$emailSender) {
$emailSender = $siteINI->variable('MailSettings', 'AdminEmail');
}
if ($transport == 'SMTP') {
$mailTransport = new ezcMailSmtpTransport($siteINI->variable('MailSettings', 'TransportServer'), $siteINI->variable('MailSettings', 'TransportUser'), $siteINI->variable('MailSettings', 'TransportPassword'), $siteINI->variable('MailSettings', 'TransportPort'));
} else {
eZDebug::writeError('Only SMTP Transport supported', 'jajNewsletterSubscription::sendConfirmationMail');
throw new Exception('Only SMTP Transport supported');
}
$mail = new ezcMailComposer();
$mail->charset = $charset;
$mail->subjectCharset = $charset;
$mail->subject = $subject;
$mail->htmlText = $body;
$mail->from = ezcMailTools::parseEmailAddress($emailSender, $charset);
$mail->addTo(new ezcMailAddress($to, '', $charset));
$mail->build();
$mailTransport->send($mail);
}
示例3: testFoldAny76LongWord
public function testFoldAny76LongWord()
{
$reference = "Thisisalongwordthatismorethan76characterslong.Let'sseehowthisishandledbyourlittlefolder That was the first space.";
ezcMailHeaderFolder::setLimit(ezcMailHeaderFolder::SOFT_LIMIT);
$folded = ezcMailHeaderFolder::foldAny($reference);
$exploded = explode(ezcMailTools::lineBreak(), $folded);
$this->assertEquals(2, count($exploded));
$this->assertEquals(87, strlen($exploded[0]));
$this->assertEquals(26, strlen($exploded[1]));
}
示例4: generateHeaders
/**
* Override of original {@link ezcMail::generateHeaders()}.
* Allows headers customization
*
* @return string The mail headers
*/
public function generateHeaders()
{
// Workaround for encoded email addresses.
// When encoded, email addresses (at least the name param) have more characters
// By default, line length is set to 76 characters, after what a new line is created with $lineBreak.
// This operation is done during encoding via iconv (see ezcMailTools::composeEmailAddress()).
// Problem is that this operation is done a 2nd time in ezcMailPart::generateHeaders().
// Following code ensures that there is no double $lineBreak introduced
// by this process because it potentially breaks headers
$lineBreak = ezcMailTools::lineBreak();
$headers = str_replace("{$lineBreak}{$lineBreak}", $lineBreak, parent::generateHeaders());
return $headers;
}
示例5: send
/**
* Sends the mail $mail using the PHP mail method.
*
* Note that a message may not arrive at the destination even though
* it was accepted for delivery.
*
* @throws ezcMailTransportException
* if the mail was not accepted for delivery by the MTA.
* @param ezcMail $mail
*/
public function send(ezcMail $mail)
{
$mail->appendExcludeHeaders(array('to', 'subject'));
$headers = rtrim($mail->generateHeaders());
// rtrim removes the linebreak at the end, mail doesn't want it.
if (count($mail->to) + count($mail->cc) + count($mail->bcc) < 1) {
throw new ezcMailTransportException('No recipient addresses found in message header.');
}
$additionalParameters = "";
if (isset($mail->returnPath)) {
$additionalParameters = "-f{$mail->returnPath->email}";
}
$success = mail(ezcMailTools::composeEmailAddresses($mail->to), $mail->getHeader('Subject'), $mail->generateBody(), $headers, $additionalParameters);
if ($success === false) {
throw new ezcMailTransportException('The email could not be sent by sendmail');
}
}
示例6: addRelatedPart
/**
* Adds $part to the list of parts and returns the Content-ID of the part.
*
* @param ezcMailPart $part
* @return string
*/
public function addRelatedPart(ezcMailPart $part)
{
// it doesn't have a Content-ID, we must set one.
$contentId = '';
if ($part->getHeader('Content-ID') == '') {
if ($part instanceof ezcMailFile) {
$part->contentId = ezcMailTools::generateContentId(basename($part->fileName));
} else {
$part->setHeader('Content-ID', ezcMailTools::generateContentId('part'));
}
}
$contentId = trim($part->getHeader('Content-ID'), '<>');
// Set the content ID property of the ezcMailFile if one was found
if ($part instanceof ezcMailFile) {
$part->contentId = $contentId;
}
if (count($this->parts) > 0) {
$this->parts[] = $part;
} else {
$this->parts[1] = $part;
}
return $contentId;
}
示例7: generateHtmlPart
/**
* Returns an ezcMailPart based on the HTML provided.
*
* This method adds local files/images to the mail itself using a
* {@link ezcMailMultipartRelated} object.
*
* @throws ezcBaseFileNotFoundException
* if $fileName does not exists.
* @throws ezcBaseFilePermissionProblem
* if $fileName could not be read.
* @return ezcMailPart
*/
private function generateHtmlPart()
{
$result = false;
if ($this->htmlText != '') {
$matches = array();
if ($this->options->automaticImageInclude === true) {
// recognize file:// and file:///, pick out the image, add it as a part and then..:)
preg_match_all("/<img[\\s\\*\\s]src=[\\'\"]file:\\/\\/([^ >\\'\"]+)/i", $this->htmlText, $matches);
// pictures/files can be added multiple times. We only need them once.
$matches = array_unique($matches[1]);
}
$result = new ezcMailText($this->htmlText, $this->charset, $this->encoding);
$result->subType = "html";
if (count($matches) > 0) {
$htmlPart = $result;
// wrap already existing message in an alternative part
$result = new ezcMailMultipartRelated($result);
// create a filepart and add it to the related part
// also store the ID for each part since we need those
// when we replace the originals in the HTML message.
foreach ($matches as $fileName) {
if (is_readable($fileName)) {
// @todo waiting for fix of the fileinfo extension
// $contents = file_get_contents( $fileName );
$mimeType = null;
$contentType = null;
if (ezcBaseFeatures::hasExtensionSupport('fileinfo')) {
// if fileinfo extension is available
$filePart = new ezcMailFile($fileName);
} elseif (ezcMailTools::guessContentType($fileName, $contentType, $mimeType)) {
// if fileinfo extension is not available try to get content/mime type
// from the file extension
$filePart = new ezcMailFile($fileName, $contentType, $mimeType);
} else {
// fallback in case fileinfo is not available and could not get content/mime
// type from file extension
$filePart = new ezcMailFile($fileName, "application", "octet-stream");
}
$cid = $result->addRelatedPart($filePart);
// replace the original file reference with a reference to the cid
$this->htmlText = str_replace('file://' . $fileName, 'cid:' . $cid, $this->htmlText);
} else {
if (file_exists($fileName)) {
throw new ezcBaseFilePermissionException($fileName, ezcBaseFileException::READ);
} else {
throw new ezcBaseFileNotFoundException($fileName);
}
// throw
}
}
// update mail, with replaced URLs
$htmlPart->text = $this->htmlText;
}
}
return $result;
}
示例8: generate
/**
* Returns the complete mail part including both the header and the body
* as a string.
*
* @return string
*/
public function generate()
{
return $this->generateHeaders() . ezcMailTools::lineBreak() . $this->generateBody();
}
示例9: testFoldingAddresses
public function testFoldingAddresses()
{
$this->mail->from = new ezcMailAddress('from@ez.no');
$addresses = array('nospam1@ez.no', 'nospam2@ez.no', 'nospam3@ez.no', 'nospam4@ez.no', 'nospam5@ez.no', 'nospam6@ez.no', 'nospam7@ez.no');
foreach ($addresses as $address) {
$this->mail->addBcc(new ezcMailAddress($address));
}
$expected = "From: from@ez.no" . ezcMailTools::lineBreak() . "To: " . ezcMailTools::lineBreak() . "Bcc: nospam1@ez.no, nospam2@ez.no, nospam3@ez.no, nospam4@ez.no, nospam5@ez.no," . ezcMailTools::lineBreak() . " nospam6@ez.no, nospam7@ez.no" . ezcMailTools::lineBreak() . "Subject: " . ezcMailTools::lineBreak() . "MIME-Version: 1.0" . ezcMailTools::lineBreak() . "User-Agent: eZ Components";
$return = $this->mail->generate();
// cut away the Date and Message-ID headers as there is no way to predict what they will be
$return = join(ezcMailTools::lineBreak(), array_slice(explode(ezcMailTools::lineBreak(), $return), 0, 7));
$this->assertEquals($expected, $return);
}
示例10: tempnam
$newFile = tempnam($this->dir, 'mail');
copy($mailPart->fileName, $newFile);
// save location and setup ID array
$this->cids[$mailPart->contentId] = $this->webDir . '/' . basename($newFile);
}
// if we find a text part and if the sub-type is HTML (no plain text)
// we store that in the classes' htmlText property.
if ($mailPart instanceof ezcMailText) {
if ($mailPart->subType == 'html') {
$this->htmlText = $mailPart->text;
}
}
}
}
// create the collector class and set the filesystem path, and the webserver's
// path to find the attached files (images) in.
$collector = new collector();
$collector->dir = "/home/httpd/html/test/ezc";
$collector->webDir = '/test/ezc';
// We use the saveMailPart() method of the $collector object function as a
// callback in walkParts().
$context = new ezcMailPartWalkContext(array($collector, 'saveMailPart'));
// only call the callback for file and text parts.
$context->filter = array('ezcMailFile', 'ezcMailText');
// use walkParts() to iterate over all parts in the first parsed e-mail
// message.
$mail[0]->walkParts($context, $mail[0]);
// display the html text with the content IDs replaced with references to the
// file in the webroot.
echo ezcMailTools::replaceContentIdRefs($collector->htmlText, $collector->cids);
示例11: foldAny
/**
* Returns $text folded to the 998 character limit on any whitespace.
*
* The algorithm tries to minimize the number of comparisons by searching
* backwards from the maximum number of allowed characters on a line.
*
* @param string $text
* @return string
*/
public static function foldAny($text)
{
// Don't fold unless we have to.
if (strlen($text) <= self::$limit) {
return $text;
}
// go to 998'th char.
// search back to whitespace
// fold
$length = strlen($text);
$folded = "";
// find first occurence of whitespace searching backwards
$search = 0;
$previousFold = 0;
while ($search + self::$limit < $length) {
// search from the max possible length of the substring
$search += self::$limit;
while ($text[$search] != " " && $text[$search] != "\t" && $search > $previousFold) {
$search--;
}
if ($search == $previousFold) {
// continuous string of more than limit chars.
// We will just have to continue searching forwards to the next whitespace instead
// This is not confirming to standard.. but what can we do?
$search += self::$limit;
// back to where we started
while ($search < $length && $text[$search] != " " && $text[$search] != "\t") {
$search++;
}
}
// lets fold
if ($folded === "") {
$folded = substr($text, $previousFold, $search - $previousFold);
} else {
$folded .= ezcMailTools::lineBreak() . substr($text, $previousFold, $search - $previousFold);
}
$previousFold = $search;
}
// we need to append the rest if there is any
if ($search < $length) {
$folded .= ezcMailTools::lineBreak() . substr($text, $search);
}
return $folded;
}
示例12: addHeadersSection
/**
* Returns the generated text for a section of the delivery-status part.
*
* @param ezcMailHeadersHolder $headers
* @return string
*/
private function addHeadersSection(ezcMailHeadersHolder $headers)
{
$result = "";
foreach ($headers->getCaseSensitiveArray() as $header => $value) {
$result .= $header . ": " . $value . ezcMailTools::lineBreak();
}
return $result;
}
示例13: testNoDoubleFold
public function testNoDoubleFold()
{
$composedAddress = ezcMailTools::composeEmailAddress(new ezcMailAddress('foo@bar.com', 'From name ØÆÅ test test test test with a very long name which contains norwegian characters ÆØÅæøÅ', 'utf-8'));
$this->assertSame($composedAddress, ezcMailHeaderFolder::foldAny($composedAddress));
}
示例14: generateHtmlPart
/**
* Returns an ezcMailPart based on the HTML provided.
*
* This method adds local files/images to the mail itself using a
* {@link ezcMailMultipartRelated} object.
*
* @throws ezcBaseFileNotFoundException
* if $fileName does not exists.
* @throws ezcBaseFilePermissionProblem
* if $fileName could not be read.
* @return ezcMailPart
*/
private function generateHtmlPart()
{
$result = false;
if ($this->htmlText != '') {
$matches = array();
if ($this->options->automaticImageInclude === true) {
/*
1.7.1 regex is buggy filename are not extract correctly
http://issues.ez.no/IssueView.php?Id=16612&
preg_match_all( '(
<img \\s+[^>]*
src\\s*=\\s*
(?:
(?# Match quoted attribute)
([\'"])file://(?P<quoted>[^>]+)\\1
(?# Match unquoted attribute, which may not contain spaces)
| file://(?P<unquoted>[^>\\s]+)
)
[^>]* >)ix', $htmlText, $matches );
* */
// CJW Newsletter regex change only find all file://ezroot/
// so it is secure
// recognize file://ezroot/ and pick out the image, add it as a part and then..:)
preg_match_all("/<img[\\s\\*\\s]src=[\\'\"]file:\\/\\/ezroot\\/([^ >\\'\"]+)/i", $this->htmlText, $matches);
// pictures/files can be added multiple times. We only need them once.
$matches = array_unique($matches[1]);
}
$result = new ezcMailText($this->htmlText, $this->charset, $this->encoding);
$result->subType = "html";
if (count($matches) > 0) {
$htmlPart = $result;
// wrap already existing message in an alternative part
$result = new ezcMailMultipartRelated($result);
// create a filepart and add it to the related part
// also store the ID for each part since we need those
// when we replace the originals in the HTML message.
foreach ($matches as $fileName) {
if (is_readable($fileName)) {
// @todo waiting for fix of the fileinfo extension
// $contents = file_get_contents( $fileName );
$mimeType = null;
$contentType = null;
if (ezcBaseFeatures::hasExtensionSupport('fileinfo')) {
// if fileinfo extension is available
$filePart = new ezcMailFile($fileName);
} elseif (ezcMailTools::guessContentType($fileName, $contentType, $mimeType)) {
// if fileinfo extension is not available try to get content/mime type
// from the file extension
$filePart = new ezcMailFile($fileName, $contentType, $mimeType);
} else {
// fallback in case fileinfo is not available and could not get content/mime
// type from file extension
$filePart = new ezcMailFile($fileName, "application", "octet-stream");
}
$cid = $result->addRelatedPart($filePart);
// replace the original file reference with a reference to the cid
$this->htmlText = str_replace('file://ezroot/' . $fileName, 'cid:' . $cid, $this->htmlText);
} else {
if (file_exists($fileName)) {
throw new ezcBaseFilePermissionException($fileName, ezcBaseFileException::READ);
} else {
throw new ezcBaseFileNotFoundException($fileName);
}
// throw
}
}
// update mail, with replaced URLs
$htmlPart->text = $this->htmlText;
}
}
return $result;
}
示例15: parseContentDisposition
/**
* Returns the a ezcMailContentDispositionHeader for the parsed $header.
*
* If $cd is provided this object will be used to fill in the blanks. This function
* will not clear out any old values in the object.
*
* @param string $header
* @param ezcMailContentDispositionHeader $cd
* @return ezcMailContentDispositionHeader
*/
public static function parseContentDisposition($header, ezcMailContentDispositionHeader $cd = null)
{
if ($cd === null) {
$cd = new ezcMailContentDispositionHeader();
}
$parsedHeader = self::parseHeader($header);
$cd->disposition = $parsedHeader[0];
if (isset($parsedHeader[1])) {
foreach ($parsedHeader[1] as $paramName => $data) {
switch ($paramName) {
case 'filename':
$cd->fileName = $data['value'];
$cd->displayFileName = trim($data['value'], '"');
if (isset($data['charset'])) {
$cd->fileNameCharSet = $data['charset'];
$cd->displayFileName = ezcMailCharsetConverter::convertToUTF8Iconv($cd->displayFileName, $cd->fileNameCharSet);
} else {
if (preg_match('@^=\\?[^?]+\\?[QqBb]\\?@', $cd->displayFileName)) {
$cd->displayFileName = ezcMailTools::mimeDecode($cd->displayFileName);
}
}
if (isset($data['language'])) {
$cd->fileNameLanguage = $data['language'];
}
break;
case 'creation-date':
$cd->creationDate = $data['value'];
break;
case 'modification-date':
$cd->modificationDate = $data['value'];
break;
case 'read-date':
$cd->readDate = $data['value'];
break;
case 'size':
$cd->size = $data['value'];
break;
default:
$cd->additionalParameters[$paramName] = $data['value'];
if (isset($data['charset'])) {
$cd->additionalParametersMetaData[$paramName]['charSet'] = $data['charset'];
}
if (isset($data['language'])) {
$cd->additionalParametersMetaData[$paramName]['language'] = $data['language'];
}
break;
}
}
}
return $cd;
}