本文整理汇总了PHP中Swift_SendmailTransport类的典型用法代码示例。如果您正苦于以下问题:PHP Swift_SendmailTransport类的具体用法?PHP Swift_SendmailTransport怎么用?PHP Swift_SendmailTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Swift_SendmailTransport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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('me@ff.com')->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);
}
示例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'));
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例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('noreply@nckidsinc.com' => 'North Country Kids, Inc.'))->setTo(array($to_address, 'm.decker@nckidsinc.com'))->setBody($mailBody, 'text/html');
// queue it up
$mailer->send($message);
$mail_count++;
}
}
}
return $this->renderText($mail_count . ' messages have been sent.');
}
示例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;
}
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
}
示例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;
}
}
示例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);
}