本文整理汇总了PHP中Swift_Preferences::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Preferences::getInstance方法的具体用法?PHP Swift_Preferences::getInstance怎么用?PHP Swift_Preferences::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Preferences
的用法示例。
在下文中一共展示了Swift_Preferences::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendEmail
/**
* Send email using swift api.
*
* @param $body
* @param $recipients
* @param $from
* @param $subject
*/
public function sendEmail($body, $recipients, $from, $subject)
{
$config = Zend_Registry::get('config');
$failures = '';
Swift_Preferences::getInstance()->setCharset('UTF-8');
//Create the Transport
$transport = Swift_SmtpTransport::newInstance($config->mail->server->name, $config->mail->server->port, $config->mail->server->security)->setUsername($config->mail->username)->setPassword($config->mail->password);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$headers = $message->getHeaders();
$headers->addTextHeader("signed-by", Constant::EMAIL_DOMAIN);
//Give the message a subject
$message->setSubject($subject);
//Set the From address with an associative array
$message->setFrom($from);
//Set the To addresses with an associative array
$message->setTo($recipients);
//Give it a body
$message->setBody($body);
$message->setContentType("text/html");
//Send the message
$myresult = $mailer->batchSend($message);
if ($myresult) {
return null;
} else {
return Constant::EMAIL_FAIL_MESSAGE;
}
}
示例2: setUp
public function setUp()
{
$this->_attFileName = 'data.txt';
$this->_attFileType = 'text/plain';
$this->_attFile = __DIR__ . '/../../_samples/files/data.txt';
Swift_Preferences::getInstance()->setCharset('utf-8');
}
示例3: testDotStuffingEncodingAndDecodingSamplesFromDiConfiguredInstance
public function testDotStuffingEncodingAndDecodingSamplesFromDiConfiguredInstance()
{
// Enable DotEscaping
Swift_Preferences::getInstance()->setQPDotEscape(true);
$this->testEncodingAndDecodingSamplesFromDiConfiguredInstance();
// Disable DotStuffing to continue
Swift_Preferences::getInstance()->setQPDotEscape(false);
}
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:8,代码来源:QpContentEncoderAcceptanceTest.php
示例4: __construct
/**
*
* @param \Swift_Transport $transport
*/
public function __construct(\Zend_Config $webconfig)
{
$this->setWebconfig($webconfig);
if (null === $transport) {
$transport = $this->createTransport();
}
parent::__construct($transport);
\Swift_Preferences::getInstance()->setCharset('iso-8859-1');
}
示例5: sendHtmlMail
public function sendHtmlMail($from, $to, $subject, $body, $attachments = array())
{
spl_autoload_unregister(array('YiiBase', 'autoload'));
Yii::import('application.extensions.swift.swift_required', true);
spl_autoload_register(array('YiiBase', 'autoload'));
Swift_Preferences::getInstance()->setCharset('utf-8');
$message = Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setTo($to)->setBody($body, 'text/html');
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
return $mailer->batchSend($message);
}
示例6: __construct
/**
* Swift初期化
*
* @param String $host
* @param String $port
* @param String $user
* @param String $pass
* @param String $charset
* @return vold
* @codeCoverageIgnore
*/
public function __construct($host, $port, $user, $pass, $charset = 'iso-2022-jp')
{
$this->host = $host;
$this->port = $port;
$this->user = $user;
$this->pass = $pass;
$this->charset = $charset;
$this->setPath();
\Swift::init(function () use($charset) {
\Swift_DependencyContainer::getInstance()->register('mime.qpheaderencoder')->asAliasOf('mime.base64headerencoder');
\Swift_Preferences::getInstance()->setCharset($charset);
});
}
示例7: _preferences
protected function _preferences()
{
// Sets the default charset so that setCharset() is not needed elsewhere
\Swift_Preferences::getInstance()->setCharset('utf-8');
// Without these lines the default caching mechanism is "array" but this uses a lot of memory
// If possible, use a disk cache to enable attaching large attachments etc.
// You can override the default temporary directory by setting the TMPDIR environment variable.
// if (function_exists('sys_get_temp_dir') && is_writable(sys_get_temp_dir())) {
// \Swift_Preferences::getInstance()
// ->setTempDir(sys_get_temp_dir())
// ->setCacheType('disk');
// }
\Swift_Preferences::getInstance()->setTempDir(self::getPathTmp())->setCacheType('disk');
\Swift_Preferences::getInstance()->setQPDotEscape(false);
}
示例8: __construct
/**
* Load our Email setting from `app/config/email.php` over riding any values set in `app/config/dev.email.php` if the
* application is in `DEV_MODE`.
*
*
* @return void
*/
public function __construct()
{
if (is_file(\App::path() . '/app/config/email.php')) {
$this->settings = (require \App::path() . '/app/config/email.php');
}
//if
if (\App::devMode()) {
$devSettings = \App::path() . '/app/config/dev.email.php';
if (is_file($devSettings)) {
$this->settings = array_merge($this->settings, require $devSettings);
}
//if
}
//if
$charset = $this->getSetting('CHARSET');
if (!$charset) {
$charset = 'iso-8859-2';
}
//if
\Swift_Preferences::getInstance()->setCharset($charset);
}
示例9: mf_send_resume_link
function mf_send_resume_link($dbh, $form_name, $form_resume_url, $resume_email)
{
global $mf_lang;
//get settings first
$mf_settings = mf_get_settings($dbh);
$subject = sprintf($mf_lang['resume_email_subject'], $form_name);
$email_content = sprintf($mf_lang['resume_email_content'], $form_name, $form_resume_url, $form_resume_url);
$subject = utf8_encode($subject);
//create the mail transport
if (!empty($mf_settings['smtp_enable'])) {
$s_transport = Swift_SmtpTransport::newInstance($mf_settings['smtp_host'], $mf_settings['smtp_port']);
if (!empty($mf_settings['smtp_secure'])) {
$s_transport->setEncryption('tls');
}
if (!empty($mf_settings['smtp_auth'])) {
$s_transport->setUsername($mf_settings['smtp_username']);
$s_transport->setPassword($mf_settings['smtp_password']);
}
} else {
$s_transport = Swift_MailTransport::newInstance();
//use PHP mail() transport
}
//create mailer instance
$s_mailer = Swift_Mailer::newInstance($s_transport);
if (file_exists($mf_settings['upload_dir'] . "/form_{$form_id}/files")) {
Swift_Preferences::getInstance()->setCacheType('disk')->setTempDir($mf_settings['upload_dir'] . "/form_{$form_id}/files");
}
$from_name = html_entity_decode($mf_settings['default_from_name'], ENT_QUOTES);
$from_email = $mf_settings['default_from_email'];
if (!empty($resume_email) && !empty($form_resume_url)) {
$s_message = Swift_Message::newInstance()->setCharset('utf-8')->setMaxLineLength(1000)->setSubject($subject)->setFrom(array($from_email => $from_name))->setSender($from_email)->setReturnPath($from_email)->setTo($resume_email)->setBody($email_content, 'text/html');
//send the message
$send_result = $s_mailer->send($s_message);
if (empty($send_result)) {
echo "Error sending email!";
}
}
}
示例10: job_run_archive
/**
* @param $job_object
* @return bool
*/
public function job_run_archive(&$job_object)
{
$job_object->substeps_todo = 1;
$job_object->log(sprintf(__('%d. Try to send backup with email …', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']), E_USER_NOTICE);
//check file Size
if (!empty($job_object->job['emailefilesize'])) {
if ($job_object->backup_filesize > $job_object->job['emailefilesize'] * 1024 * 1024) {
$job_object->log(__('Backup archive too big to be sent by email!', 'backwpup'), E_USER_ERROR);
$job_object->substeps_done = 1;
return TRUE;
}
}
$job_object->log(sprintf(__('Sending email to %s…', 'backwpup'), $job_object->job['emailaddress']), E_USER_NOTICE);
//get mail settings
$emailmethod = 'mail';
$emailsendmail = '';
$emailhost = '';
$emailhostport = '';
$emailsecure = '';
$emailuser = '';
$emailpass = '';
if (empty($job_object->job['emailmethod'])) {
//do so if i'm the wp_mail to get the settings
global $phpmailer;
// (Re)create it, if it's gone missing
if (!is_object($phpmailer) || !$phpmailer instanceof PHPMailer) {
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer(true);
}
//only if PHPMailer really used
if (is_object($phpmailer)) {
do_action_ref_array('phpmailer_init', array(&$phpmailer));
//get settings from PHPMailer
$emailmethod = $phpmailer->Mailer;
$emailsendmail = $phpmailer->Sendmail;
$emailhost = $phpmailer->Host;
$emailhostport = $phpmailer->Port;
$emailsecure = $phpmailer->SMTPSecure;
$emailuser = $phpmailer->Username;
$emailpass = $phpmailer->Password;
}
} else {
$emailmethod = $job_object->job['emailmethod'];
$emailsendmail = $job_object->job['emailsendmail'];
$emailhost = $job_object->job['emailhost'];
$emailhostport = $job_object->job['emailhostport'];
$emailsecure = $job_object->job['emailsecure'];
$emailuser = $job_object->job['emailuser'];
$emailpass = BackWPup_Encryption::decrypt($job_object->job['emailpass']);
}
//Generate mail with Swift Mailer
if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
try {
//Set Temp dir for mailing
Swift_Preferences::getInstance()->setTempDir(untrailingslashit(BackWPup::get_plugin_data('TEMP')))->setCacheType('disk');
// Create the Transport
if ($emailmethod == 'smtp') {
$transport = Swift_SmtpTransport::newInstance($emailhost, $emailhostport);
$transport->setUsername($emailuser);
$transport->setPassword($emailpass);
if ($emailsecure == 'ssl') {
$transport->setEncryption('ssl');
}
if ($emailsecure == 'tls') {
$transport->setEncryption('tls');
}
} elseif ($emailmethod == 'sendmail') {
$transport = Swift_SendmailTransport::newInstance($emailsendmail);
} else {
$job_object->need_free_memory($job_object->backup_filesize * 8);
$transport = Swift_MailTransport::newInstance();
}
// Create the Mailer using your created Transport
$emailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance(sprintf(__('BackWPup archive from %1$s: %2$s', 'backwpup'), date_i18n('d-M-Y H:i', $job_object->start_time, TRUE), esc_attr($job_object->job['name'])));
$message->setFrom(array($job_object->job['emailsndemail'] => $job_object->job['emailsndemailname']));
$message->setTo(array($job_object->job['emailaddress']));
$message->setBody(sprintf(__('Backup archive: %s', 'backwpup'), $job_object->backup_file), 'text/plain', strtolower(get_bloginfo('charset')));
$message->attach(Swift_Attachment::fromPath($job_object->backup_folder . $job_object->backup_file, $job_object->get_mime_type($job_object->backup_folder . $job_object->backup_file)));
// Send the message
$result = $emailer->send($message);
} catch (Exception $e) {
$job_object->log('Swift Mailer: ' . $e->getMessage(), E_USER_ERROR);
}
if (isset($mbEncoding)) {
mb_internal_encoding($mbEncoding);
}
if (isset($result) && !$result) {
$job_object->log(__('Error while sending email!', 'backwpup'), E_USER_ERROR);
return FALSE;
} else {
//.........这里部分代码省略.........
示例11: catch
*/
try {
ClassLoader::scanAndRegister();
} catch (UnresolvableDependenciesException $e) {
die($e->getMessage());
// see #6343
}
/**
* Include the Composer autoloader
*/
require_once TL_ROOT . '/vendor/autoload.php';
/**
* Override some SwiftMailer defaults
*/
Swift::init(function () {
$preferences = Swift_Preferences::getInstance();
if (!Config::get('useFTP')) {
$preferences->setTempDir(TL_ROOT . '/system/tmp')->setCacheType('disk');
}
$preferences->setCharset(Config::get('characterSet'));
});
/**
* Define the relative path to the installation (see #5339)
*/
if (file_exists(TL_ROOT . '/system/config/pathconfig.php') && TL_SCRIPT != 'contao/install.php') {
define('TL_PATH', include TL_ROOT . '/system/config/pathconfig.php');
} elseif (TL_MODE == 'BE') {
define('TL_PATH', preg_replace('/\\/contao\\/[a-z]+\\.php$/i', '', Environment::get('scriptName')));
} else {
define('TL_PATH', null);
// cannot be reliably determined
示例12: __construct
/**
* Constructor.
*
* Available options:
*
* * charset: The default charset to use for messages
* * logging: Whether to enable logging or not
* * delivery_strategy: The delivery strategy to use
* * spool_class: The spool class (for the spool strategy)
* * spool_arguments: The arguments to pass to the spool constructor
* * delivery_address: The email address to use for the single_address strategy
* * transport: The main transport configuration
* * * class: The main transport class
* * * param: The main transport parameters
*
* @param sfEventDispatcher $dispatcher An event dispatcher instance
* @param array $options An array of options
*/
public function __construct(sfEventDispatcher $dispatcher, $options)
{
// options
$options = array_merge(array('charset' => 'UTF-8', 'logging' => false, 'delivery_strategy' => 'realtime', 'transport' => array('class' => 'Swift_MailTransport', 'param' => array())), $options);
$constantName = 'sfMailer::' . strtoupper($options['delivery_strategy']);
$this->strategy = defined($constantName) ? constant($constantName) : false;
if (!$this->strategy) {
throw new InvalidArgumentException(sprintf('Unknown mail delivery strategy "%s" (should be one of realtime, spool, single_address, or none)', $options['delivery_strategy']));
}
// transport
$class = $options['transport']['class'];
$transport = new $class();
if (isset($options['transport']['param'])) {
foreach ($options['transport']['param'] as $key => $value) {
$method = 'set' . ucfirst($key);
if (method_exists($transport, $method)) {
$transport->{$method}($value);
} elseif (method_exists($transport, 'getExtensionHandlers')) {
foreach ($transport->getExtensionHandlers() as $handler) {
if (in_array(strtolower($method), array_map('strtolower', (array) $handler->exposeMixinMethods()))) {
$transport->{$method}($value);
}
}
}
}
}
$this->realtimeTransport = $transport;
if (sfMailer::SPOOL == $this->strategy) {
if (!isset($options['spool_class'])) {
throw new InvalidArgumentException('For the spool mail delivery strategy, you must also define a spool_class option');
}
$arguments = isset($options['spool_arguments']) ? $options['spool_arguments'] : array();
if ($arguments) {
$r = new ReflectionClass($options['spool_class']);
$this->spool = $r->newInstanceArgs($arguments);
} else {
$this->spool = new $options['spool_class']();
}
$transport = new Swift_SpoolTransport($this->spool);
} elseif (sfMailer::SINGLE_ADDRESS == $this->strategy) {
if (!isset($options['delivery_address'])) {
throw new InvalidArgumentException('For the single_address mail delivery strategy, you must also define a delivery_address option');
}
$this->address = $options['delivery_address'];
$transport->registerPlugin($this->redirectingPlugin = new Swift_Plugins_RedirectingPlugin($this->address));
}
parent::__construct($transport);
// logger
if ($options['logging']) {
$this->logger = new sfMailerMessageLoggerPlugin($dispatcher);
$transport->registerPlugin($this->logger);
}
if (sfMailer::NONE == $this->strategy) {
// must be registered after logging
$transport->registerPlugin(new Swift_Plugins_BlackholePlugin());
}
// preferences
Swift_Preferences::getInstance()->setCharset($options['charset']);
$dispatcher->notify(new sfEvent($this, 'mailer.configure'));
}
示例13: batch
* @return integer number of emails sent
*/
public function batch(array $to, array &$failed = NULL)
{
// Get a copy of the current message
$message = clone $this->_message;
// Load the mailer instance
$mailer = Email::mailer();
// Count the total number of messages sent
$total = 0;
foreach ($to as $email => $name) {
if (ctype_digit((string) $email)) {
// Only an email address was provided
$email = $name;
$name = NULL;
}
// Set the To addre
$message->setTo($email, $name);
// Send this email
$total += $mailer->send($message, $failed);
}
return $total;
}
}
// End email
// Load Swiftmailer
require Kohana::find_file('vendor/swiftmailer', 'lib/swift_required');
if (method_exists('Swift_Preferences', 'getInstance')) {
// Set the default character set for everything
Swift_Preferences::getInstance()->setCharset(Kohana::$charset);
}
示例14: initialize
/**
* Initialise.
*
* Runs ar plugin init time.
*
* @throws InvalidArgumentException If invalid configuration given.
*
* @return void
*/
public function initialize()
{
define('SWIFT_REQUIRED_LOADED', true);
define('SWIFT_INIT_LOADED', true);
// register namespace
ZLoader::addAutoloader('Swift', dirname(__FILE__) . '/lib/vendor/SwiftMailer/classes');
// initialize Swift
//require_once realpath($this->baseDir . '/lib/vendor/SwiftMailer/swift_init.php'); // dont use this as it fails in virtual hosting environments with open_basedir restrictions
// Load in dependency maps
require_once dirname(__FILE__) . '/lib/vendor/SwiftMailer/dependency_maps/cache_deps.php';
require_once dirname(__FILE__) . '/lib/vendor/SwiftMailer/dependency_maps/mime_deps.php';
require_once dirname(__FILE__) . '/lib/vendor/SwiftMailer/dependency_maps/transport_deps.php';
// load configuration (todo: move this to persistence).
include dirname(__FILE__) . '/configuration/config.php';
$this->serviceManager['swiftmailer.preferences.sendmethod'] = $config['sendmethod'];
$preferences = Swift_Preferences::getInstance();
$this->serviceManager['swiftmailer.preferences.charset'] = $config['charset'];
$this->serviceManager['swiftmailer.preferences.cachetype'] = $config['cachetype'];
$this->serviceManager['swiftmailer.preferences.tempdir'] = $config['tempdir'];
$preferences->setCharset($config['charset']);
$preferences->setCacheType($config['cachetype']);
$preferences->setTempDir($config['tempdir']);
// determine the correct transport
$type = $config['transport']['type'];
$args = $config['transport'][$type];
switch ($type) {
case 'mail':
$this->serviceManager['swiftmailer.transport.mail.extraparams'] = $args['extraparams'];
$definition = new Zikula_ServiceManager_Definition('Swift_MailTransport', array(new Zikula_ServiceManager_Argument('swiftmailer.transport.mail.extraparams')));
break;
case 'smtp':
$this->serviceManager['swiftmailer.transport.smtp.host'] = $args['host'];
$this->serviceManager['swiftmailer.transport.smtp.port'] = $args['port'];
$definition = new Zikula_ServiceManager_Definition('Swift_SmtpTransport', array(
new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.host'),
new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.port')));
if ($args['username'] && $args['password']) {
$this->serviceManager['swiftmailer.transport.smtp.username'] = $args['username'];
$this->serviceManager['swiftmailer.transport.smtp.password'] = $args['password'];
$definition->addMethod('setUserName', new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.username'));
$definition->addMethod('setPassword', new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.password'));
}
if (isset($args['encryption'])) {
$this->serviceManager['swiftmailer.transport.smtp.encryption'] = $args['encryption'];
$definition->addMethod('setEncryption', new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.encryption'));
}
break;
case 'sendmail':
$this->serviceManager['swiftmailer.transport.mail.command'] = $args['command'];
$definition = new Zikula_ServiceManager_Definition('Swift_SendmailTransport', array(new Zikula_ServiceManager_Argument('swiftmailer.transport.mail.command')));
break;
default:
// error
throw new InvalidArgumentException('Invalid transport type, must be mail, smtp or sendmail');
break;
}
// register transport
$this->serviceManager->registerService('swiftmailer.transport', $definition);
// define and register mailer using transport service
$definition = new Zikula_ServiceManager_Definition('Swift_Mailer', array(new Zikula_ServiceManager_Reference('swiftmailer.transport')));
$this->serviceManager->registerService('mailer', $definition, false);
// register simple mailer service
$definition = new Zikula_ServiceManager_Definition('SystemPlugins_SwiftMailer_Mailer', array(new Zikula_ServiceManager_Reference('zikula.servicemanager')));
$this->serviceManager->registerService('mailer.simple', $definition);
}
示例15: swiftmailer_configurator
function swiftmailer_configurator()
{
Swift_Preferences::getInstance()->setCharset(JsonApiApplication::$charset);
}