当前位置: 首页>>代码示例>>PHP>>正文


PHP MailUtility::mail方法代码示例

本文整理汇总了PHP中TYPO3\CMS\Core\Utility\MailUtility::mail方法的典型用法代码示例。如果您正苦于以下问题:PHP MailUtility::mail方法的具体用法?PHP MailUtility::mail怎么用?PHP MailUtility::mail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TYPO3\CMS\Core\Utility\MailUtility的用法示例。


在下文中一共展示了MailUtility::mail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doMailCallsHook

 /**
  * Method called from tests mailCallsHook() and mailCallsHookWithDefaultMailFrom().
  */
 protected function doMailCallsHook($fromAddress = '', $fromName = '')
 {
     // Backup configuration
     $mailConfigurationBackup = $GLOBALS['TYPO3_CONF_VARS']['MAIL'];
     $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'] = $fromAddress;
     $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'] = $fromName;
     $to = 'john@example.com';
     $subject = 'Good news everybody!';
     $messageBody = 'The hooks works!';
     $additionalHeaders = 'Reply-to: jane@example.com';
     $additionalParameters = '-f postmaster@example.com';
     $fakeThis = FALSE;
     $additionalHeadersExpected = $additionalHeaders;
     if ($fromAddress !== '' && $fromName !== '') {
         $additionalHeadersExpected .= LF . sprintf('From: "%s" <%s>', $fromName, $fromAddress);
     }
     $mockMailer = $this->getMock('TYPO3\\CMS\\Core\\Mail\\MailerAdapterInterface', array('mail'));
     $mockClassName = get_class($mockMailer);
     \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($mockClassName, $mockMailer);
     $mockMailer->expects($this->once())->method('mail')->with($to, $subject, $messageBody, $additionalHeadersExpected, $additionalParameters, $fakeThis)->will($this->returnValue(TRUE));
     $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'] = array($mockClassName);
     \TYPO3\CMS\Core\Utility\MailUtility::mail($to, $subject, $messageBody, $additionalHeaders, $additionalParameters);
     // Restore configuration
     $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = $mailConfigurationBackup;
 }
开发者ID:khanhdeux,项目名称:typo3test,代码行数:28,代码来源:MailUtilityTest.php

示例2: plainMailEncoded

 /**
  * Simple substitute for the PHP function mail() which allows you to specify encoding and character set
  * The fifth parameter ($encoding) will allow you to specify 'base64' encryption for the output (set $encoding=base64)
  * Further the output has the charset set to UTF-8 by default.
  *
  * @param string $email Email address to send to. (see PHP function mail())
  * @param string $subject Subject line, non-encoded. (see PHP function mail())
  * @param string $message Message content, non-encoded. (see PHP function mail())
  * @param string $headers Headers, separated by LF
  * @param string $encoding Encoding type: "base64", "quoted-printable", "8bit". Default value is "quoted-printable".
  * @param string $charset Charset used in encoding-headers (only if $encoding is set to a valid value which produces such a header)
  * @param boolean $dontEncodeHeader If set, the header content will not be encoded
  * @return boolean TRUE if mail was accepted for delivery, FALSE otherwise
  * @deprecated since 6.1, will be removed two versions later - Use \TYPO3\CMS\Core\Mail\Mailer instead
  */
 public static function plainMailEncoded($email, $subject, $message, $headers = '', $encoding = 'quoted-printable', $charset = '', $dontEncodeHeader = FALSE)
 {
     self::logDeprecatedFunction();
     if (!$charset) {
         $charset = 'utf-8';
     }
     $email = self::normalizeMailAddress($email);
     if (!$dontEncodeHeader) {
         // Mail headers must be ASCII, therefore we convert the whole header to either base64 or quoted_printable
         $newHeaders = array();
         // Split the header in lines and convert each line separately
         foreach (explode(LF, $headers) as $line) {
             // Field tags must not be encoded
             $parts = explode(': ', $line, 2);
             if (count($parts) == 2) {
                 if (0 == strcasecmp($parts[0], 'from')) {
                     $parts[1] = self::normalizeMailAddress($parts[1]);
                 }
                 $parts[1] = self::encodeHeader($parts[1], $encoding, $charset);
                 $newHeaders[] = implode(': ', $parts);
             } else {
                 // Should never happen - is such a mail header valid? Anyway, just add the unchanged line...
                 $newHeaders[] = $line;
             }
         }
         $headers = implode(LF, $newHeaders);
         unset($newHeaders);
         // Email address must not be encoded, but it could be appended by a name which should be so (e.g. "Kasper Skårhøj <kasperYYYY@typo3.com>")
         $email = self::encodeHeader($email, $encoding, $charset);
         $subject = self::encodeHeader($subject, $encoding, $charset);
     }
     switch ((string) $encoding) {
         case 'base64':
             $headers = trim($headers) . LF . 'Mime-Version: 1.0' . LF . 'Content-Type: text/plain; charset="' . $charset . '"' . LF . 'Content-Transfer-Encoding: base64';
             // Adding LF because I think MS outlook 2002 wants it... may be removed later again.
             $message = trim(chunk_split(base64_encode($message . LF))) . LF;
             break;
         case '8bit':
             $headers = trim($headers) . LF . 'Mime-Version: 1.0' . LF . 'Content-Type: text/plain; charset=' . $charset . LF . 'Content-Transfer-Encoding: 8bit';
             break;
         case 'quoted-printable':
         default:
             $headers = trim($headers) . LF . 'Mime-Version: 1.0' . LF . 'Content-Type: text/plain; charset=' . $charset . LF . 'Content-Transfer-Encoding: quoted-printable';
             $message = self::quoted_printable($message);
     }
     // Headers must be separated by CRLF according to RFC 2822, not just LF.
     // But many servers (Gmail, for example) behave incorrectly and want only LF.
     // So we stick to LF in all cases.
     // Make sure no empty lines are there.
     $headers = trim(implode(LF, self::trimExplode(LF, $headers, TRUE)));
     return \TYPO3\CMS\Core\Utility\MailUtility::mail($email, $subject, $message, $headers);
 }
开发者ID:KarlDennisMatthaei1923,项目名称:PierraaDesign,代码行数:67,代码来源:GeneralUtility.php


注:本文中的TYPO3\CMS\Core\Utility\MailUtility::mail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。