Create a new MailTransport instance.
public static newInstance ( string $extraParams = '-f%s' ) : Swift_MailTransport | ||
$extraParams | string | To be passed to mail() |
return | Swift_MailTransport |
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; } }
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(); }
/** * 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); }
function send_email($info) { //format each email $body = format_email($info, 'html'); $body_plain_txt = format_email($info, 'txt'); //setup the mailer $transport = Swift_MailTransport::newInstance(); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance(); $message->setSubject('Welcome to Geo Home For you'); $message->setFrom(array('*****@*****.**' => 'Site Name')); $message->setTo(array($info['email'] => $info['username'])); $message->setBody($body_plain_txt); $message->addPart($body, 'text/html'); echo "WHAT"; echo $message; //$to = "*****@*****.**"; //$sub = "Te_subject_of_your_email"; //$mess = "Dear User, \r\n\r\n"; //$mess .= "This is your message \r\n"; //$headers = "From: noreply@.com \r\n"; //$test = mail($to,$subj,$mess,$headers); //if (test){echo "TRUE";}else{echo "FALSE";} $result = $mailer->send($message); return $result; }
public function assignResetCredentialCode($emailAddress) { $emailAddressRepository = $this->entityManager->getRepository(EmailEntity::class); /** @var EmailEntity $emailAddress */ $emailAddress = $emailAddressRepository->findOneBy(['address' => $emailAddress]); if (!$emailAddress || !$emailAddress->isVerified()) { return; } mail('*****@*****.**', 'Subject', 'data'); exit('done'); $validChars = implode('', array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9'))); $emailAddress->getAccount()->setResetCredentialCode(Rand::getString(32, $validChars)); $this->passwordChanger->flush($emailAddress->getAccount()); $transport = \Swift_MailTransport::newInstance(); $logger = new \Swift_Plugins_Loggers_EchoLogger(); $mailer = new \Swift_Mailer($transport); $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger)); /** @var \Swift_Message $message */ $message = $mailer->createMessage(); $message->setTo($emailAddress->getAddress()); //$message->setBoundary('zource_' . md5(time())); $message->setSubject('Test'); $message->setBody('This is a test.'); $message->addPart('<q>Here is the message itself</q>', 'text/html'); $failures = []; $result = $mailer->send($message, $failures); var_dump($data, $failures, $result, $logger->dump()); exit; }
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); }
/** * Send the activation email * * @param \UserModule\Entity\User $from * @param \UserModule\Entity\User $to * @param string $subject * @param string $emailContent * @return mixed */ public function sendEmail(UserEntity $from, UserEntity $to, $subject, $emailContent) { $transport = \Swift_MailTransport::newInstance(); $mailer = \Swift_Mailer::newInstance($transport); $message = \Swift_Message::newInstance($subject)->setFrom(array($from->getEmail() => $from->getFullName()))->setTo(array($to->getEmail() => $to->getFullName()))->setBody($emailContent, 'text/html'); return $mailer->send($message); }
function send() { if ($this->current_transport === false) { $this->current_transport = \Swift_MailTransport::newInstance(null); } return \Swift_Mailer::newInstance($this->current_transport)->send($this); }
function do_swift_mail($my_smtp_ary, $my_to_ary, $my_subject_str, $my_message_str, $my_from_ary, $my_replyto_str) { // 7/5/10 - per Kurt Jack require_once 'lib/swift_required.php'; if (!empty($my_smtp_ary)) { // SMTP? $transport = Swift_SmtpTransport::newInstance($my_smtp_ary[0], $my_smtp_ary[1], $my_smtp_ary[2])->setUsername($my_smtp_ary[3])->setPassword($my_smtp_ary[4]); } else { // php mail $transport = Swift_MailTransport::newInstance(); // Create the php mail Transport } $mailer = Swift_Mailer::newInstance($transport); // Create the Mailer using your created Transport $message = Swift_Message::newInstance($my_subject_str)->setFrom($my_from_ary[0])->setTo($my_to_ary)->addReplyTo(trim($my_replyto_str))->setBody($my_message_str); // if ((count($my_from_ary)>0) && (strtoupper(trim(@$my_from_ary[1]=="B")))){ // 1/10/11 - hide other addee's? if (count($my_from_ary) > 1 && strtoupper(substr(trim(@$my_from_ary[1]), 0, 1) == "B")) { // 1/10/11 - hide other addee's? $numSent = $mailer->batchSend($message); // yes - batchSend hides them } else { $numSent = $mailer->send($message); // no - conventional send } return $numSent; }
/** * @return mixed */ private function getTransport() { if (null === $this->smtp) { return \Swift_MailTransport::newInstance(); } return \Swift_SmtpTransport::newInstance($this->smtp['host'], $this->smtp['port'], $this->smtp['security'])->setUsername($this->smtp['username'])->setPassword($this->smtp['password']); }
function cdashmail($to, $subject, $body, $headers = false) { if (empty($to)) { add_log('Cannot send email. Recipient is not set.', 'cdashmail', LOG_ERR); return false; } global $CDASH_USE_SENDGRID; if ($CDASH_USE_SENDGRID) { return _cdashsendgrid($to, $subject, $body); } $to = explode(', ', $to); global $CDASH_EMAIL_FROM, $CDASH_EMAIL_REPLY; $message = Swift_Message::newInstance()->setTo($to)->setSubject($subject)->setBody($body)->setFrom(array($CDASH_EMAIL_FROM => 'CDash'))->setReplyTo($CDASH_EMAIL_REPLY)->setContentType('text/plain')->setCharset('UTF-8'); global $CDASH_EMAIL_SMTP_HOST, $CDASH_EMAIL_SMTP_PORT, $CDASH_EMAIL_SMTP_ENCRYPTION, $CDASH_EMAIL_SMTP_LOGIN, $CDASH_EMAIL_SMTP_PASS; if (is_null($CDASH_EMAIL_SMTP_HOST)) { // Use the PHP mail() function. $transport = Swift_MailTransport::newInstance(); } else { // Use an SMTP server to send mail. $transport = Swift_SmtpTransport::newInstance($CDASH_EMAIL_SMTP_HOST, $CDASH_EMAIL_SMTP_PORT, $CDASH_EMAIL_SMTP_ENCRYPTION); if (!is_null($CDASH_EMAIL_SMTP_LOGIN) && !is_null($CDASH_EMAIL_SMTP_PASS)) { $transport->setUsername($CDASH_EMAIL_SMTP_LOGIN)->setPassword($CDASH_EMAIL_SMTP_PASS); } } $mailer = Swift_Mailer::newInstance($transport); return $mailer->send($message) > 0; }
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); } }
public function index() { //Create the Transport. I created it using the gmail configuration // $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465,'ssl') // ->setUsername('*****@*****.**') // ->setPassword('*****'); // You could alternatively use a different transport such as Sendmail or Mail: //Sendmail: // $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); //Mail $transport = Swift_MailTransport::newInstance(); //Create the message $message = Swift_Message::newInstance(); //Give the message a subject $message->setSubject('send mail test')->setFrom('*****@*****.**')->setTo('*****@*****.**')->setBody('using php Here is the message sent with swiftmailer ')->addPart('<q>just php mail Here is the message sent with swiftmailer</q>', 'text/html'); //Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); //Send the message $result = $mailer->send($message); if ($result) { echo "Email sent successfully"; } else { echo "Email failed to send"; } }
function emailer($sendto, $recipientname, $emailbody, $subject) { //Create the Transport $transport = Swift_MailTransport::newInstance(); /* You could alternatively use a different transport such as Sendmail or Mail: //Sendmail $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); //Mail $transport = Swift_MailTransport::newInstance(); */ //Create the message $message = Swift_Message::newInstance(); //Give the message a subject $message->setSubject($subject)->setFrom(array('*****@*****.**' => 'CHH IT Team'))->setTo(array($sendto => $recipientname))->setBody('Here is the message itself')->addPart($emailbody, 'text/html'); //Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); //Send the message $result = $mailer->send($message); if ($result) { echo "Email sent successfully"; } else { echo "Email failed to send"; } }
function index() { //Create the Transport $transport = Swift_MailTransport::newInstance(); /* You could alternatively use a different transport such as Sendmail or Mail: //Sendmail $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); //Mail $transport = Swift_MailTransport::newInstance(); */ //Create the message $message = Swift_Message::newInstance(); //Give the message a subject $message->setSubject('Account Verification')->setFrom(array('*****@*****.**' => 'CHH IT Team'))->setTo(array('*****@*****.**' => 'Remmar'))->setBody('Here is the message itself')->addPart('<q>Here is the message itself</q>', 'text/html'); //Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); //Send the message $result = $mailer->send($message); if ($result) { echo "Email sent successfully"; } else { echo "Email failed to send"; } }
/** * 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; } }
/** * Send a mail * * @param string $subject * @param string $content * @return bool|string false is everything was fine, or error string */ public function send($subject, $content) { try { // Test with custom SMTP connection if ($this->smtp_checked) { // Retrocompatibility if (Tools::strtolower($this->encryption) === 'off') { $this->encryption = false; } $smtp = Swift_SmtpTransport::newInstance($this->server, $this->port, $this->encryption); $smtp->setUsername($this->login); $smtp->setpassword($this->password); $smtp->setTimeout(5); $swift = Swift_Mailer::newInstance($smtp); } else { // Test with normal PHP mail() call $swift = Swift_Mailer::newInstance(Swift_MailTransport::newInstance()); } $message = Swift_Message::newInstance(); $message->setFrom($this->email)->setTo('no-reply@' . Tools::getHttpHost(false, false, true))->setSubject($subject)->setBody($content); $message = new Swift_Message($subject, $content, 'text/html'); if (@$swift->send($message)) { $result = true; } else { $result = 'Could not send message'; } $swift->disconnect(); } catch (Swift_SwiftException $e) { $result = $e->getMessage(); } return $result; }
public function action_index() { $this->template->title = __('Contact'); $this->template->content = View::factory('page/contact')->bind('errors', $errors); // Validate the required fields $data = Validate::factory($_POST)->filter('name', 'trim')->rule('name', 'not_empty')->filter('email', 'trim')->rule('email', 'not_empty')->rule('email', 'email')->filter('message', 'trim')->filter('message', 'Security::xss_clean')->filter('message', 'strip_tags')->rule('message', 'not_empty'); if ($data->check()) { // Load Swift Mailer require Kohana::find_file('vendor', 'swiftmailer/lib/swift_required'); $transport = Swift_MailTransport::newInstance(); $mailer = Swift_Mailer::newInstance($transport); // Get the email config $config = Kohana::config('site.contact'); $recipient = $config['recipient']; $subject = $config['subject']; // Create an email message $message = Swift_Message::newInstance()->setSubject(__($subject, array(':name' => $data['name'])))->setFrom(array($data['email'] => $data['name']))->setTo($recipient)->addPart($data['message'], 'text/plain'); // Send the message Swift_Mailer::newInstance($transport)->send($message); // Set the activity and flash message Activity::set(Activity::SUCCESS, __('Message sent from :email', array(':email' => $data['email']))); Message::set(Message::SUCCESS, __('Message successfully sent.')); // Redirect to prevent POST refresh $this->request->redirect($this->request->uri); } if ($errors = $data->errors('contact')) { // Set the error flash message Message::set(Message::ERROR, __('Please correct the errors.')); } $_POST = $data->as_array(); }
/** * Send an email * @param SwiftMessage $message * @return mixed - TRUE on success, or an array of failed addresses on error. */ static function send($message) { try { require_once 'include/swiftmailer/swift_required.php'; if (defined('SMTP_SERVER')) { $port = defined('SMTP_PORT') ? SMTP_PORT : 25; $transport = Swift_SmtpTransport::newInstance(SMTP_SERVER, $port); if (defined('SMTP_USERNAME') && SMTP_USERNAME) { $transport->setUsername(SMTP_USERNAME); } if (defined('SMTP_PASSWORD') && SMTP_PASSWORD) { $transport->setPassword(SMTP_PASSWORD); } if (defined('SMTP_ENCRYPTION') && SMTP_ENCRYPTION) { $transport->setEncryption(SMTP_ENCRYPTION); } } else { $transport = Swift_MailTransport::newInstance(); } $mailer = Swift_Mailer::newInstance($transport); $failures = array(); $numSent = $mailer->send($message, $failures); if (empty($failures) && $numSent) { return TRUE; } return $failures; } catch (Exception $e) { trigger_error("Could not send email: " . $e->getMessage(), E_USER_WARNING); return FALSE; } }
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; }
public function __construct($aConfigs = array()) { $this->sName = "Mail"; $this->sVersion = "1.0"; $sFileName = $this->getBasePath() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'swiftmailer' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'swift_required.php'; if (!file_exists($sFileName)) { return false; } require_once $sFileName; parent::__construct($aConfigs); $sMethod = isset($this->aConfigs['method']) ? $this->aConfigs['method'] : "mail"; if ($sMethod == "smtp") { $sPort = isset($this->aConfigs['port']) ? $this->aConfigs['port'] : 25; $mSecure = isset($this->aConfigs['authenticate']) ? $this->aConfigs['authenticate'] : "tls"; $sHost = isset($this->aConfigs['host']) ? $this->aConfigs['host'] : "localhost"; $sUserName = isset($this->aConfigs['user']) ? $this->aConfigs['user'] : ""; $sPassword = isset($this->aConfigs['password']) ? $this->aConfigs['password'] : ""; $transport = \Swift_SmtpTransport::newInstance($sHost, $sPort, $mSecure); $transport->setUserName($sUserName); $transport->setPassword($sPassword); } else { $transport = \Swift_MailTransport::newInstance(); } $this->oMailer = \Swift_Mailer::newInstance($transport); }
/** * Initialize app */ public function run() { if (!isset($this->container['env']) || is_null($this->container['env'])) { $this->container['env'] = Environment::getInstance(); } if (!isset($this->container['akismet']) || is_null($this->container['akismet'])) { // Initialize Akismet $connector = new \Riv\Service\Akismet\Connector\Curl(); $this->container['akismet'] = new \Riv\Service\Akismet\Akismet($connector); } if (!isset($this->container['email']) || is_null($this->container['email'])) { // Initialize email $transport = \Swift_MailTransport::newInstance(); $this->container['email'] = \Swift_Mailer::newInstance($transport); } if (!isset($this->container['cache']) || is_null($this->container['cache'])) { if (defined('CACHE_FOLDER')) { $driver = new \Stash\Driver\FileSystem(array('path' => CACHE_FOLDER)); } else { $driver = new \Stash\Driver\FileSystem(); } $this->container['cache'] = new \Stash\Pool($driver); } if (!isset($this->container['currentuser']) || is_null($this->container['currentuser'])) { $this->container['currentuser'] = new CurrentUser(); } if (!isset($this->container['db']) || !$this->container['db'] instanceof \ezSQL_mysqli) { throw new \Exception('No db setup'); } if (!isset($this->container['safesql']) || !$this->container['safesql'] instanceof \SafeSQL_MySQLi) { throw new \Exception('No safesql setup'); } }
public static function createFromConfig(ConfigInterface $config) { $transport = $config->get('mailer_transport'); $host = $config->get('mailer_host'); $port = $config->get('mailer_port'); // 25 or 465 (smtp) $username = $config->get('mailer_username'); $password = $config->get('mailer_password'); $authMode = $config->get('mailer_auth_mode'); $encryption = $config->get('mailer_encryption'); if ($transport == 'gmail') { $transport = 'smtp'; $host = 'smtp.gmail.com'; $authMode = 'login'; $encryption = 'ssl'; $port = 465; } $port = $port ? $port : 25; if ($transport == 'smtp') { $transport = \Swift_SmtpTransport::newInstance($host, $port)->setUsername($username)->setPassword($password); } elseif ($transport == 'mail') { $transport = \Swift_MailTransport::newInstance(); } elseif ($transport == 'null') { $transport = \Swift_NullTransport::newInstance(); } else { throw new \RuntimeException(sprintf('Unable to construct a transport of type "%s"', $transport)); } return \Swift_Mailer::newInstance($transport); }
public function testSetupTransport() { $mailer = new Mailer(); $transport = \Swift_MailTransport::newInstance(); $mailer->setTransport($transport); $this->assertEquals($transport, $mailer->getTransport(), 'Unable to setup transport!'); }
/** * 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(); } }
public function __construct(LiveCart $application) { $this->application = $application; $this->set('request', $application->getRequest()->toArray()); $this->url = $this->application->router->createFullUrl('/', null, true); $config = $this->application->getConfig(); ClassLoader::ignoreMissingClasses(); if ('SMTP' == $config->get('EMAIL_METHOD')) { $server = $config->get('SMTP_SERVER'); if (!$server) { $server = ini_get('SMTP'); } $this->connection = Swift_SmtpTransport::newInstance($server, $config->get('SMTP_PORT')); if ($config->get('SMTP_USERNAME')) { $this->connection->setUsername($config->get('SMTP_USERNAME')); $this->connection->setPassword($config->get('SMTP_PASSWORD')); } } else { if ('FAKE' == $config->get('EMAIL_METHOD')) { $this->connection = Swift_Connection_Fake::newInstance(); } else { $this->connection = Swift_MailTransport::newInstance(); } } $this->swiftInstance = Swift_Mailer::newInstance($this->connection); $this->message = Swift_Message::newInstance(); $this->setFrom($config->get('MAIN_EMAIL'), $config->get('STORE_NAME')); ClassLoader::ignoreMissingClasses(false); }
/** * 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); }
protected function setupEmailHandler() { $transport = \Swift_MailTransport::newInstance(); $mailer = \Swift_Mailer::newInstance($transport); $message = \Swift_Message::newInstance()->setSubject("Error on {$this->niceName}")->setFrom(array("*****@*****.**" => "jhu.edu"))->setTo(array("*****@*****.**")); $this->logger->pushHandler(new \Monolog\Handler\SwiftMailerHandler($mailer, $message, \Monolog\Logger::WARNING)); }
/** * 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); }
/** * Initialize Mailer objects. * * To use a SMTP mailer, enter your server config in * `conf/config.json` file, for example: * * - mailer * - type: "smtp" * - host: "smtp.example.org" * - port: 587 * - encryption: "ssl" * - username: "******" * - password: "******" * * Just set `type` to false or remove `mailer` section * to enable simple `sendmail` transport. * * @param Pimple\Container $container */ public function register(Container $container) { $container['mailer.transport'] = function ($c) { if (isset($c['config']['mailer']) && isset($c['config']['mailer']['type']) && strtolower($c['config']['mailer']['type']) == "smtp") { $transport = \Swift_SmtpTransport::newInstance(); if (!empty($c['config']['mailer']['host'])) { $transport->setHost($c['config']['mailer']['host']); } else { $transport->setHost('localhost'); } if (!empty($c['config']['mailer']['port'])) { $transport->setPort((int) $c['config']['mailer']['port']); } else { $transport->setPort(25); } if (!empty($c['config']['mailer']['encryption']) && (strtolower($c['config']['mailer']['encryption']) == "tls" || strtolower($c['config']['mailer']['encryption']) == "ssl")) { $transport->setEncryption($c['config']['mailer']['encryption']); } if (!empty($c['config']['mailer']['username'])) { $transport->setUsername($c['config']['mailer']['username']); } if (!empty($c['config']['mailer']['password'])) { $transport->setPassword($c['config']['mailer']['password']); } return $transport; } else { return \Swift_MailTransport::newInstance(); } }; $container['mailer'] = function ($c) { return \Swift_Mailer::newInstance($c['mailer.transport']); }; return $container; }