本文整理汇总了PHP中Swift_Preferences类的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Preferences类的具体用法?PHP Swift_Preferences怎么用?PHP Swift_Preferences使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Swift_Preferences类的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: getInstance
/**
* Gets the instance of Preferences.
*
* @return Swift_Preferences
*/
public static function getInstance()
{
if (!isset(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
示例4: 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
示例5: __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');
}
示例6: 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);
}
示例7: __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);
});
}
示例8: _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);
}
示例9: __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);
}
示例10: swiftmailer_configurator
function swiftmailer_configurator()
{
Swift_Preferences::getInstance()->setCharset(JsonApiApplication::$charset);
}
示例11: 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!";
}
}
}
示例12: 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 {
//.........这里部分代码省略.........
示例13: 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
示例14: setUp
public function setUp()
{
Swift_Preferences::getInstance()->setCharset('utf-8');
}
示例15:
<?php
require __DIR__ . '/../vendor/autoload.php';
\Swift::init(function () {
\Swift_DependencyContainer::getInstance()->register('mime.qpheaderencoder')->asAliasOf('mime.base64headerencoder');
\Swift_Preferences::getInstance()->setCharset('iso-2022-jp');
});
$message = \Swift_Message::newInstance()->setSubject('件名')->setFrom(['jhon_doe@example.jp' => 'テスト送信者'])->setTo(['uzulla@example.jp'])->setBody("メール本文です\n1234567890\nあいうえおかきくけko\n")->setCharset('iso-2022-jp')->setEncoder(new \Swift_Mime_ContentEncoder_PlainContentEncoder('7bit'));
$transport = \Swift_MailTransport::newInstance();
$mailer = \Swift_Mailer::newInstance($transport);
$mailer->send($message);
echo "sent\n";