本文整理汇总了PHP中Swift_SendmailTransport类的典型用法代码示例。如果您正苦于以下问题:PHP Swift_SendmailTransport类的具体用法?PHP Swift_SendmailTransport怎么用?PHP Swift_SendmailTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Swift_SendmailTransport类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: initializeMailer
/**
* Instantiates and configures Swift Mailer.
*/
private function initializeMailer()
{
switch ($this->options['method']) {
case 'smtp':
$transport = \Swift_SmtpTransport::newInstance($this->options['host'], $this->options['port'], $this->options['encryption']);
//->setUsername('[email protected]')->setPassword('pass');
break;
case 'sendmail':
$transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
break;
case 'exim':
$transport = \Swift_SendmailTransport::newInstance('/usr/sbin/exim -bs');
break;
case 'qmail':
$transport = \Swift_SendmailTransport::newInstance('/usr/sbin/qmail -bs');
break;
case 'postfix':
$transport = \Swift_SendmailTransport::newInstance('/usr/sbin/postfix -bs');
break;
case 'mail':
default:
$transport = \Swift_MailTransport::newInstance();
}
// Create the Mailer using the created Transport
$this->mailer = \Swift_Mailer::newInstance($transport);
}
开发者ID:ksst,项目名称:kf,代码行数:29,代码来源:SwiftMailer.php
示例2: __construct
public function __construct($key)
{
parent::__construct();
$newPassword = uniqid();
$reset = \Pecee\Model\User\UserReset::confirm($key, $newPassword);
if ($reset) {
$user = ModelUser::getById($reset);
if ($user->hasRow()) {
// Send mail with new password
// TODO: Move this shit to separate html template
$user->setEmailConfirmed(true);
$user->update();
$text = "Dear customer!\n\nWe've reset your password - you can login with your e-mail and the new password provided below:\nNew password: " . $newPassword . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team";
$transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
$swift = \Swift_Mailer::newInstance($transport);
$message = new \Swift_Message(lang('New password for NinjaImg'));
$message->setFrom(env('MAIL_FROM'));
$message->setSender(env('MAIL_FROM'));
$message->setReplyTo(env('MAIL_FROM'));
$message->setBody($text, 'text/plain');
$message->setTo($user->username);
$swift->send($message);
$this->setMessage('A new password has been sent to your e-mail.', 'success');
redirect(url('user.login'));
}
redirect(url('home'));
}
}
开发者ID:Monori,项目名称:imgservice,代码行数:28,代码来源:UserReset.php
示例3: initialize
public function initialize()
{
require_once TD_INC . 'swift/swift_required.php';
if ($this->config['transport'] == 'smtp') {
$this->transport = Swift_SmtpTransport::newInstance($this->config['smtp_host']);
if ($this->config['smtp_port']) {
$this->transport->setPort($this->config['smtp_port']);
}
if ($this->config['smtp_encryption']) {
$this->transport->setEncryption($this->config['smtp_encryption']);
}
if ($this->config['smtp_user']) {
$this->transport->setUsername($this->config['smtp_user']);
}
if ($this->config['smtp_pass']) {
$this->transport->setPassword($this->config['smtp_pass']);
}
if ($this->config['smtp_timeout']) {
$this->transport->setTimeout($this->config['smtp_timeout']);
}
} elseif ($this->config['transport'] == 'sendmail') {
$this->transport = Swift_SendmailTransport::newInstance();
if ($this->config['sendmail_command']) {
$this->transport->setCommand($this->config['sendmail_command']);
}
} elseif ($this->config['transport'] == 'mail') {
$this->transport = Swift_MailTransport::newInstance();
}
$this->mailer = Swift_Mailer::newInstance($this->transport);
}
开发者ID:purna89,项目名称:TrellisDesk,代码行数:30,代码来源:class_email.php
示例4: __construct
/**
* Class constructor.
* Load all data from configurations and generate the initial clases
* to manage the email
*
* @param string Content type for message body. It usually text/plain or text/html.
* Default is 'text/plain' but can be changed later
*/
public function __construct($content_type = 'text/plain')
{
$config = RMFunctions::configs();
$config_handler =& xoops_gethandler('config');
$xconfig = $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
// Instantiate the Swit Transport according to our preferences
// We can change this preferences later
switch ($config['transport']) {
case 'mail':
$this->swTransport = Swift_MailTransport::newInstance();
break;
case 'smtp':
$this->swTransport = Swift_SmtpTransport::newInstance($config['smtp_server'], $config['smtp_port'], $config['smtp_crypt'] != 'none' ? $config['smtp_crypt'] : '');
$this->swTransport->setUsername($config['smtp_user']);
$this->swTransport->setPassword($config['smtp_pass']);
break;
case 'sendmail':
$this->swTransport = Swift_SendmailTransport::newInstance($config['sendmail_path']);
break;
}
// Create the message object
// Also this object could be change later with message() method
$this->swMessage = Swift_Message::newInstance();
$this->swMessage->setReplyTo($xconfig['from']);
$this->swMessage->setFrom(array($xconfig['from'] => $xconfig['fromname']));
$this->swMessage->setContentType($content_type);
}
开发者ID:laiello,项目名称:bitcero-modules,代码行数:35,代码来源:mailer.php
示例5: __construct
public function __construct(KConfig $config = null)
{
parent::__construct($config);
$this->_message = Swift_Message::newInstance();
switch ($config->method) {
case 'sendmail':
// WIP required -bs or -t switch
$transport = Swift_SendmailTransport::newInstance($config->sendmail);
break;
case 'smtp':
if ($config->smtpauth == 1) {
if ($config->smtpsecure != "none") {
$transport = Swift_SmtpTransport::newInstance($config->smtphost, $config->smtpport, $config->smtpsecure)->setUsername($config->smtpuser)->setPassword($config->smtppass);
} else {
$transport = Swift_SmtpTransport::newInstance($config->smtphost, $config->smtpport)->setUsername($config->smtpuser)->setPassword($config->smtppass);
}
} else {
if ($config->smtpsecure != "none") {
$transport = Swift_SmtpTransport::newInstance($config->smtphost, $config->smtpport, $config->smtpsecure);
} else {
$transport = Swift_SmtpTransport::newInstance($config->smtphost, $config->smtpport);
}
}
break;
case 'spool':
// TODO: Make spool options configurable.
$transport = Swift_SpoolTransport::newInstance(new Swift_FileSpool('/var/spool/swift'));
break;
case 'mail':
default:
$transport = Swift_MailTransport::newInstance();
break;
}
$this->_mailer = Swift_Mailer::newInstance($transport);
}
开发者ID:JSWebdesign,项目名称:intranet-platform,代码行数:35,代码来源:mail.php
示例6: send
/**
* @param array $to
* @param string $fromEmail
* @param string $fromName
* @param string $subject
* @param string $body
* @param string $contentType
* @param array $cc
* @param array $bcc
* @return mixed
*/
function send(array $to, $fromEmail, $fromName, $subject, $body, $contentType = 'text/html', $cc = [], $bcc = [])
{
$message = new \Swift_Message($subject, $body, $contentType);
$message->setFrom($fromEmail, $fromName);
foreach (['to' => 'addTo', 'cc' => 'addCc', 'bcc' => 'addBcc'] as $type => $method) {
foreach (${$type} as $item) {
if (is_array($item)) {
$message->{$method}($item['email'], $item['name']);
} else {
$message->{$method}($item);
}
}
}
$mailer = new \Swift_SendmailTransport();
$mailer->send($message);
}
开发者ID:apitude,项目名称:apitude,代码行数:27,代码来源:SimpleSender.php
示例7: loadConfig
/**
* Parse the configuration file
*
* @param array $parsedConfig
*/
private function loadConfig($parsedConfig)
{
if (isset($parsedConfig['moduleConf']['Type']) && $parsedConfig['moduleConf']['Type'] == "smtp") {
$this->transport = \Swift_SmtpTransport::newInstance();
if (isset($parsedConfig['moduleConf']['Host']) && $parsedConfig['moduleConf']['Host'] != "") {
$this->transport->setHost($parsedConfig['moduleConf']['Host']);
}
if (isset($parsedConfig['moduleConf']['Port']) && $parsedConfig['moduleConf']['Port'] != "") {
$this->transport->setPort($parsedConfig['moduleConf']['Port']);
}
if (isset($parsedConfig['moduleConf']['Username']) && $parsedConfig['moduleConf']['Username'] != "") {
$this->transport->setUsername($parsedConfig['moduleConf']['Username']);
}
if (isset($parsedConfig['moduleConf']['Password']) && $parsedConfig['moduleConf']['Password'] != "") {
$this->transport->setPassword($parsedConfig['moduleConf']['Password']);
}
if (isset($parsedConfig['moduleConf']['Encryption']) && $parsedConfig['moduleConf']['Encryption'] != "") {
$this->transport->setEncryption($parsedConfig['moduleConf']['Encryption']);
}
} elseif (isset($parsedConfig['moduleConf']['Type']) && $parsedConfig['moduleConf']['Type'] == "sendmail") {
$this->transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
} else {
$this->transport = \Swift_MailTransport::newInstance();
}
}
开发者ID:stonedz,项目名称:pff2,代码行数:30,代码来源:Mail.php
示例8: executeEmailExpirationNotice
public function executeEmailExpirationNotice(sfWebRequest $request)
{
$notices = $request->getParameter('expired');
$mail_count = 0;
// prepare swift mailer
require_once sfConfig::get('sf_lib_dir') . '/vendor/swift/swift_required.php';
# needed due to symfony autoloader
$mailer = Swift_Mailer::newInstance(Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -t'));
foreach ($notices as $emp_id => $notices) {
$employee = EmployeePeer::retrieveByPK($emp_id);
if ($employee) {
foreach ($notices as $notice => $expired) {
// queue an email of type $notice with this $employee's info
switch ($notice) {
case 'tb_date':
$type = 'Tb';
break;
case 'physical_date':
$type = 'Physical';
break;
}
$mailBody = $this->getPartial('employee/emailExpired' . $type, array('name' => $employee->getFullname(), 'expiration' => $expired));
$to_address = $employee->getCompanyEmail() ? $employee->getCompanyEmail() : $employee->getPersonalEmail();
$message = Swift_Message::newInstance('Expired ' . $type . ' Notice')->setFrom(array('[email protected]' => 'North Country Kids, Inc.'))->setTo(array($to_address, '[email protected]'))->setBody($mailBody, 'text/html');
// queue it up
$mailer->send($message);
$mail_count++;
}
}
}
return $this->renderText($mail_count . ' messages have been sent.');
}
开发者ID:anvaya,项目名称:nckids,代码行数:32,代码来源:actions.class.php
示例9: setTransport
/**
* Define the transport method
* @param object $okt
*/
protected function setTransport()
{
switch ($this->okt->config->email['transport']) {
default:
case 'mail':
$this->transport = Swift_MailTransport::newInstance();
break;
case 'smtp':
$this->transport = Swift_SmtpTransport::newInstance($this->okt->config->email['smtp']['host'], $this->okt->config->email['smtp']['port']);
if (!empty($this->okt->config->email['smtp']['username'])) {
$this->transport->setUsername($this->okt->config->email['smtp']['username']);
}
if (!empty($this->okt->config->courriel['smtp']['password'])) {
$this->transport->setPassword($this->okt->config->email['smtp']['password']);
}
break;
case 'sendmail':
$command = '/usr/sbin/exim -bs';
if (!empty($this->okt->config->email['sendmail'])) {
$command = $this->okt->config->email['sendmail'];
}
$this->transport = Swift_SendmailTransport::newInstance($command);
break;
}
}
开发者ID:jewelhuq,项目名称:okatea,代码行数:29,代码来源:class.oktMail.php
示例10: getMailer
protected function getMailer()
{
if (empty($this->mailer)) {
require_once PATH_SYSTEM . "/vendors/Swift-4.0.4/lib/swift_required.php";
switch ($this->emailMode) {
case 'smtp':
//Create the Transport
$transport = Swift_SmtpTransport::newInstance($this->emailConfig['host'], $this->emailConfig['port']);
if (!empty($this->emailConfig['user'])) {
$transport->setUsername($this->emailConfig['user']);
}
if (!empty($this->emailConfig['password'])) {
$transport->setPassword($this->emailConfig['password']);
}
if (!empty($this->emailConfig['timeout'])) {
$transport->setTimeout($this->emailConfig['timeout']);
}
if (!empty($this->emailConfig['encryption'])) {
$transport->setEncryption($this->emailConfig['encryption']);
}
$this->mailer = Swift_Mailer::newInstance($transport);
break;
case 'sendmail':
$transport = Swift_SendmailTransport::newInstance(!empty($this->emailConfig['pathToSendmail']) ? $this->emailConfig['pathToSendmail'] : '/usr/sbin/sendmail -bs');
$this->mailer = Swift_Mailer::newInstance($transport);
break;
default:
case 'mail':
$transport = Swift_MailTransport::newInstance();
$this->mailer = Swift_Mailer::newInstance($transport);
break;
}
}
return $this->mailer;
}
开发者ID:wb-crowdfusion,项目名称:crowdfusion,代码行数:35,代码来源:Email.php
示例11: __construct
/**
* Base constructor.
* In the base constructor the bridge gets the mailer configuration.
*
* @param ConfigObject $config The base configuration.
*
* @throws SwiftMailerException
*/
public function __construct($config)
{
$this->config = $config;
$transportType = strtolower($config->get('Transport.Type', 'mail'));
$disableDelivery = $config->get('DisableDelivery', false);
if ($disableDelivery) {
$transportType = 'null';
}
// create Transport instance
switch ($transportType) {
case 'smtp':
$transport = \Swift_SmtpTransport::newInstance($config->get('Transport.Host', 'localhost'), $config->get('Transport.Port', 25), $config->get('Transport.AuthMode', null));
$transport->setUsername($config->get('Transport.Username', ''));
$transport->setPassword($config->get('Transport.Password', ''));
$transport->setEncryption($config->get('Transport.Encryption', null));
break;
case 'mail':
$transport = \Swift_MailTransport::newInstance();
break;
case 'sendmail':
$transport = \Swift_SendmailTransport::newInstance($config->get('Transport.Command', '/usr/sbin/sendmail -bs'));
break;
case 'null':
$transport = \Swift_NullTransport::newInstance();
break;
default:
throw new SwiftMailerException('Invalid transport.type provided.
Supported types are [smtp, mail, sendmail, null].');
break;
}
// create Mailer instance
$this->mailer = \Swift_Mailer::newInstance($transport);
// register plugins
$this->registerPlugins($config);
}
开发者ID:Nkelliny,项目名称:Framework,代码行数:43,代码来源:Transport.php
示例12: __construct
function __construct()
{
// include swift mailer
require ENGINE_PATH . 'swiftmailer/classes/Swift.php';
Swift::init();
Swift::registerAutoload();
//Yii::import('system.vendors.swiftMailer.classes.Swift', true);
//Yii::registerAutoloader(array('Swift','autoload'));
require_once ENGINE_PATH . 'swiftmailer/swift_init.php';
//Yii::import('system.vendors.swiftMailer.swift_init', true);
switch ($this->params['transportType']) {
case 'smtp':
$transport = Swift_SmtpTransport::newInstance($this->params['smtpServer'], $this->params['smtpPort'], $this->params['smtpSequre'])->setUsername($this->params['smtpUsername'])->setPassword($this->params['smtpPassword']);
break;
case 'sendmail':
$transport = Swift_SendmailTransport::newInstance($this->params['sendmailCommand']);
break;
default:
case 'mail':
$transport = Swift_MailTransport::newInstance();
break;
}
$this->toEmail = 'noreplay@' . $_SERVER['HTTP_HOST'];
$this->fromEmail = 'noreplay@' . $_SERVER['HTTP_HOST'];
$this->path = "http://" . $_SERVER['HTTP_HOST'] . "/submit/mailtpl/";
$this->mailer = Swift_Mailer::newInstance($transport);
$this->mes = Swift_Message::newInstance();
}
开发者ID:rjon76,项目名称:netspotapp,代码行数:28,代码来源:classEmailReporter.php
示例13: send
static function send($title, $body, $to_array, $attachment = null, $log = true)
{
$model = Config::find()->one();
// Create the message
$message = \Swift_Message::newInstance()->setSubject($title)->setFrom(array($model->from_email => $model->from_name))->setTo($to_array)->setBody($body);
// Optionally add any attachments
if ($attachment) {
if (is_array($attachment)) {
foreach ($attachment as $file) {
$message = $message->attach(Swift_Attachment::fromPath($file));
}
} else {
$message = $message->attach(Swift_Attachment::fromPath($attachment));
}
}
// Create the Transport
switch ($model->type) {
case 1:
$transport = \Swift_SmtpTransport::newInstance($model->smtp, $model->port > 0 ?: 25)->setUsername($model->from_email)->setPassword($model->pass);
break;
case 2:
$transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
break;
case 3:
$transport = \Swift_MailTransport::newInstance();
break;
}
$mailer = \Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
//log send mail
if (true === $log) {
static::log($to_array, $title, $body, $attachment);
}
}
开发者ID:rocketyang,项目名称:mincms,代码行数:34,代码来源:Mailer.php
示例14: getTransport
public function getTransport()
{
// Get Joomla mailer
$config = JFactory::getConfig();
$jmailer = $config->get('mailer');
switch ($jmailer) {
case 'sendmail':
$this->transport = Swift_SendmailTransport::newInstance($config->get('sendmail') . ' -bs');
break;
case 'smtp':
$this->transport = Swift_SmtpTransport::newInstance($config->get('smtphost'), $config->get('smtpport'));
if ($config->get('smtpauth') == 1) {
$smtpUser = $config->get('smtpuser');
$smtpPass = $config->get('smtppass');
if (!empty($smtpUser) && !empty($smtpPass)) {
$this->transport->setUsername($smtpUser)->setPassword($smtpPass);
}
$smtpEncryption = $config->get('smtpsecure');
if (!empty($smtpEncryption)) {
$this->transport->setEncryption($smtpEncryption);
}
}
break;
default:
case 'mail':
$this->transport = Swift_MailTransport::newInstance();
break;
}
}
开发者ID:prox91,项目名称:joomla-dev,代码行数:29,代码来源:mail.php
示例15: connect
/**
* Creates a SwiftMailer instance.
*
* @param string DSN connection string
* @return object Swift object
*/
public static function connect($config = NULL)
{
// Load default configuration
$config === NULL and $config = Kohana::$config->load('email');
switch ($config['driver']) {
case 'smtp':
// Set port
$port = empty($config['options']['port']) ? 25 : (int) $config['options']['port'];
// Create SMTP Transport
$transport = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port);
if (!empty($config['options']['encryption'])) {
// Set encryption
$transport->setEncryption($config['options']['encryption']);
}
// Do authentication, if part of the DSN
empty($config['options']['username']) or $transport->setUsername($config['options']['username']);
empty($config['options']['password']) or $transport->setPassword($config['options']['password']);
// Set the timeout to 5 seconds
$transport->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
break;
case 'sendmail':
// Create a sendmail connection
$transport = Swift_SendmailTransport::newInstance(empty($config['options']) ? "/usr/sbin/sendmail -bs" : $config['options']);
break;
default:
// Use the native connection
$transport = Swift_MailTransport::newInstance();
break;
}
// Create the SwiftMailer instance
return self::$_mail = Swift_Mailer::newInstance($transport);
}
开发者ID:rrsc,项目名称:beansbooks,代码行数:38,代码来源:core.php
示例16: __construct
public function __construct()
{
parent::__construct();
$this->prependSiteTitle(lang('Recover log in'));
if ($this->isPostBack()) {
$this->post->email->addValidation(new ValidateInputNotNullOrEmpty());
if (!$this->hasErrors()) {
$user = ModelUser::getByUsername($this->input('email'));
if (!$user->hasRow()) {
$this->setMessage('No user found', 'warning');
response()->refresh();
}
if (!$this->hasErrors()) {
$reset = new UserReset($user->id);
$reset->save();
// TODO: Move this shit to seperate html template
$text = "Dear customer!\n\nYou are receiving this mail, because you (or someone else) has requested a password reset for your user on NinjaImg.com.\n\nTo continue with the password reset, please click the link below to confirm the reset:\n\n" . sprintf('https://%s/reset/%s', $_SERVER['HTTP_HOST'], $reset->key) . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team";
$transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
$swift = \Swift_Mailer::newInstance($transport);
$message = new \Swift_Message(lang('Confirm password reset on NinjaImg'));
$message->setFrom(env('MAIL_FROM'));
$message->setSender(env('MAIL_FROM'));
$message->setReplyTo(env('MAIL_FROM'));
$message->setBody($text, 'text/plain');
$message->setTo($user->username);
$swift->send($message);
$this->setMessage('A password reset link has been sent to your e-mail', 'success');
// Send mail to user confirming reset...
// Maybe show message with text that are active even when session disappear
response()->refresh();
}
}
}
}
开发者ID:Monori,项目名称:imgservice,代码行数:34,代码来源:UserForgot.php
示例17: setup
/**
* Sets up the Aimeos environemnt
*
* @param string $extdir Absolute or relative path to the Aimeos extension directory
* @return \Aimeos\Slim\Bootstrap Self instance
*/
public function setup($extdir = '../ext')
{
$container = $this->app->getContainer();
$container['router'] = function ($c) {
return new \Aimeos\Slim\Router();
};
$container['mailer'] = function ($c) {
return \Swift_Mailer::newInstance(\Swift_SendmailTransport::newInstance());
};
$default = (require __DIR__ . DIRECTORY_SEPARATOR . 'aimeos-default.php');
$settings = array_replace_recursive($default, $this->settings);
$container['aimeos'] = function ($c) use($extdir) {
return new \Aimeos\Bootstrap((array) $extdir, false);
};
$container['aimeos_config'] = function ($c) use($settings) {
return new \Aimeos\Slim\Base\Config($c, $settings);
};
$container['aimeos_context'] = function ($c) {
return new \Aimeos\Slim\Base\Context($c);
};
$container['aimeos_i18n'] = function ($c) {
return new \Aimeos\Slim\Base\I18n($c);
};
$container['aimeos_locale'] = function ($c) {
return new \Aimeos\Slim\Base\Locale($c);
};
$container['aimeos_page'] = function ($c) {
return new \Aimeos\Slim\Base\Page($c);
};
$container['aimeos_view'] = function ($c) {
return new \Aimeos\Slim\Base\View($c);
};
return $this;
}
开发者ID:aimeos,项目名称:aimeos-slim,代码行数:40,代码来源:Bootstrap.php
示例18: testGetSendMailInstanceSendMailQmail
public function testGetSendMailInstanceSendMailQmail() {
$this->config
->expects($this->once())
->method('getSystemValue')
->with('mail_smtpmode', 'sendmail')
->will($this->returnValue('qmail'));
$this->assertEquals(\Swift_SendmailTransport::newInstance('/var/qmail/bin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance'));
}
开发者ID:ninjasilicon,项目名称:core,代码行数:9,代码来源:mailer.php
示例19: initTransport
/**
* @param string $transport_name the transport name
*/
protected function initTransport($transport_name)
{
if ('sendmail' == $transport_name) {
$transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
} else {
$config = $this->transports_config[$transport_name];
$transport = \Swift_SmtpTransport::newInstance($config['hostname'], $config['port'], $config['security'])->setUsername($config['username'])->setPassword($config['password']);
}
$this->transports[$transport_name] = \Swift_Mailer::newInstance($transport);
}
开发者ID:natxet,项目名称:operacore,代码行数:13,代码来源:Mailer.php
示例20: connect
/**
* Creates a SwiftMailer instance.
*
* @param string DSN connection string
* @return object Swift object
*/
public static function connect($config = NULL)
{
if (!class_exists('Swift', FALSE)) {
// Load SwiftMailer
require_once Kohana::find_file('vendor', 'swiftmailer/swift_required');
}
// Load default configuration
$config === NULL and $config = Kohana::config('email');
switch ($config['driver']) {
case 'smtp':
// Set port
$port = empty($config['options']['port']) ? NULL : (int) $config['options']['port'];
// Create a SMTP connection
$connection = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port);
if (!empty($config['options']['encryption'])) {
// Set encryption
switch (strtolower($config['options']['encryption'])) {
case 'tls':
case 'ssl':
$connection->setEncryption($config['options']['encryption']);
break;
}
}
// Do authentication, if part of the DSN
empty($config['options']['username']) or $connection->setUsername($config['options']['username']);
empty($config['options']['password']) or $connection->setPassword($config['options']['password']);
if (!empty($config['options']['auth'])) {
// Get the class name and params
list($class, $params) = arr::callback_string($config['options']['auth']);
if ($class === 'PopB4Smtp') {
// Load the PopB4Smtp class manually, due to its odd filename
require Kohana::find_file('vendor', 'swift/Swift/Authenticator/$PopB4Smtp$');
}
// Prepare the class name for auto-loading
$class = 'Swift_Authenticator_' . $class;
// Attach the authenticator
$connection->attachAuthenticator($params === NULL ? new $class() : new $class($params[0]));
}
// Set the timeout to 5 seconds
$connection->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
break;
case 'sendmail':
// Create a sendmail connection
$connection = Swift_SendmailTransport::newInstance($config['options']);
break;
default:
// Use the native connection
$connection = Swift_MailTransport::newInstance();
break;
}
// Create the SwiftMailer instance
return email::$mail = Swift_Mailer::newInstance($connection);
}
开发者ID:AsteriaGamer,项目名称:steamdriven-kohana,代码行数:59,代码来源:email.php
注:本文中的Swift_SendmailTransport类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论