本文整理汇总了PHP中Swift_Message::setPriority方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::setPriority方法的具体用法?PHP Swift_Message::setPriority怎么用?PHP Swift_Message::setPriority使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::setPriority方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendTo
/**
* Send the e-mail
*
* Friendly name portions (e.g. Admin <admin@example.com>) are allowed. The
* method takes an unlimited number of recipient addresses.
*
* @return boolean True if the e-mail was sent successfully
*/
public function sendTo()
{
$arrRecipients = $this->compileRecipients(func_get_args());
if (empty($arrRecipients)) {
return false;
}
$this->objMessage->setTo($arrRecipients);
$this->objMessage->setCharset($this->strCharset);
$this->objMessage->setPriority($this->intPriority);
// Default subject
if ($this->strSubject == '') {
$this->strSubject = 'No subject';
}
$this->objMessage->setSubject($this->strSubject);
// HTML e-mail
if ($this->strHtml != '') {
// Embed images
if ($this->blnEmbedImages) {
if ($this->strImageDir == '') {
$this->strImageDir = TL_ROOT . '/';
}
$arrCid = array();
$arrMatches = array();
$strBase = \Environment::get('base');
// Thanks to @ofriedrich and @aschempp (see #4562)
preg_match_all('/<[a-z][a-z0-9]*\\b[^>]*((src=|background=|url\\()["\']??)(.+\\.(jpe?g|png|gif|bmp|tiff?|swf))(["\' ]??(\\)??))[^>]*>/Ui', $this->strHtml, $arrMatches);
// Check for internal images
if (!empty($arrMatches) && isset($arrMatches[0])) {
for ($i = 0, $c = count($arrMatches[0]); $i < $c; $i++) {
$url = $arrMatches[3][$i];
// Try to remove the base URL
$src = str_replace($strBase, '', $url);
$src = rawurldecode($src);
// see #3713
// Embed the image if the URL is now relative
if (!preg_match('@^https?://@', $src) && file_exists($this->strImageDir . $src)) {
if (!isset($arrCid[$src])) {
$arrCid[$src] = $this->objMessage->embed(\Swift_EmbeddedFile::fromPath($this->strImageDir . $src));
}
$this->strHtml = str_replace($arrMatches[1][$i] . $arrMatches[3][$i] . $arrMatches[5][$i], $arrMatches[1][$i] . $arrCid[$src] . $arrMatches[5][$i], $this->strHtml);
}
}
}
}
$this->objMessage->setBody($this->strHtml, 'text/html');
}
// Text content
if ($this->strText != '') {
if ($this->strHtml != '') {
$this->objMessage->addPart($this->strText, 'text/plain');
} else {
$this->objMessage->setBody($this->strText, 'text/plain');
}
}
// Add the administrator e-mail as default sender
if ($this->strSender == '') {
list($this->strSenderName, $this->strSender) = \String::splitFriendlyEmail(\Config::get('adminEmail'));
}
// Sender
if ($this->strSenderName != '') {
$this->objMessage->setFrom(array($this->strSender => $this->strSenderName));
} else {
$this->objMessage->setFrom($this->strSender);
}
// Set the return path (see #5004)
$this->objMessage->setReturnPath($this->strSender);
// Send e-mail
$intSent = self::$objMailer->send($this->objMessage, $this->arrFailures);
// Log failures
if (!empty($this->arrFailures)) {
log_message('E-mail address rejected: ' . implode(', ', $this->arrFailures), $this->strLogFile);
}
// Return if no e-mails have been sent
if ($intSent < 1) {
return false;
}
$arrCc = $this->objMessage->getCc();
$arrBcc = $this->objMessage->getBcc();
// Add a log entry
$strMessage = 'An e-mail has been sent to ' . implode(', ', array_keys($this->objMessage->getTo()));
if (!empty($arrCc)) {
$strMessage .= ', CC to ' . implode(', ', array_keys($arrCc));
}
if (!empty($arrBcc)) {
$strMessage .= ', BCC to ' . implode(', ', array_keys($arrBcc));
}
log_message($strMessage, $this->strLogFile);
return true;
}
示例2: __construct
public function __construct(ConfigObject $config = null)
{
$this->message = new \Swift_Message();
if ($config) {
$this->message->setCharset($config->get('CharacterSet', 'utf-8'));
$this->message->setMaxLineLength($config->get('MaxLineLength', 78));
if ($config->get('Priority', false)) {
$this->message->setPriority($config->get('Priority', 3));
}
}
}
示例3: testSend
public function testSend()
{
$message = new Swift_Message();
$message->setFrom('johnny5@example.com', 'Johnny #5');
$message->setSubject('Is alive!');
$message->addTo('you@example.com', 'A. Friend');
$message->addTo('you+two@example.com');
$message->addCc('another+1@example.com');
$message->addCc('another+2@example.com', 'Extra 2');
$message->addBcc('another+3@example.com');
$message->addBcc('another+4@example.com', 'Extra 4');
$message->addPart('<q>Help me Rhonda</q>', 'text/html');
$message->addPart('Doo-wah-ditty.', 'text/plain');
$attachment = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
$attachment2 = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
$attachment2->setDisposition('inline');
$message->attach($attachment);
$message->attach($attachment2);
$message->setPriority(1);
$headers = $message->getHeaders();
$headers->addTextHeader('X-PM-Tag', 'movie-quotes');
$messageId = $headers->get('Message-ID')->getId();
$transport = new PostmarkTransportStub('TESTING_SERVER');
$client = $this->getMock('GuzzleHttp\\Client', array('request'));
$transport->setHttpClient($client);
$o = PHP_OS;
$v = phpversion();
$client->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('https://api.postmarkapp.com/email'), $this->equalTo(['headers' => ['X-Postmark-Server-Token' => 'TESTING_SERVER', 'User-Agent' => "swiftmailer-postmark (PHP Version: {$v}, OS: {$o})", 'Content-Type' => 'application/json'], 'json' => ['From' => '"Johnny #5" <johnny5@example.com>', 'To' => '"A. Friend" <you@example.com>,you+two@example.com', 'Cc' => 'another+1@example.com,"Extra 2" <another+2@example.com>', 'Bcc' => 'another+3@example.com,"Extra 4" <another+4@example.com>', 'Subject' => 'Is alive!', 'Tag' => 'movie-quotes', 'TextBody' => 'Doo-wah-ditty.', 'HtmlBody' => '<q>Help me Rhonda</q>', 'Headers' => [['Name' => 'Message-ID', 'Value' => '<' . $messageId . '>'], ['Name' => 'X-PM-KeepID', 'Value' => 'true'], ['Name' => 'X-Priority', 'Value' => '1 (Highest)']], 'Attachments' => [['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt'], ['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt', 'ContentID' => 'cid:' . $attachment2->getId()]]]]));
$transport->send($message);
}
示例4: createMessage
/**
* Create message from config params
*
* @param $subject
* @param $message
* @param array $placeholders email message placeholders in body
*
*/
public function createMessage($subject, $message, array $placeholders = [])
{
// get mail configurations
$config = $this->getConfig();
// add smtp exception plugin to resolve SMTP errors
$this->mailer->registerPlugin(new MailSMTPException());
// add decorator plugin to resolve messages placeholders
$this->mailer->registerPlugin(new \Swift_Plugins_DecoratorPlugin($placeholders));
// prepare message to transport
$this->message = \Swift_Message::newInstance();
$this->message->setFrom([$config['fromEmail'] => $config['fromName']]);
$this->message->setSubject($subject);
$this->message->setBody($message, 'text/html');
$this->message->setCharset('UTF-8');
$this->message->setReadReceiptTo($config['fromEmail']);
$this->message->setPriority(1);
}
示例5: setPriority
/**
* Set the priority of this message.
* The value is an integer where 1 is the highest priority and 5 is the lowest.
*
* Modified version to also accept a string $message->setPriority('high');
*
* @param mixed $priority integer|string
* @return object
*/
public function setPriority($priority)
{
if (is_string($priority)) {
switch (strtolower($priority)) {
case 'high':
$priority = 1;
break;
case 'normal':
$priority = 3;
break;
case 'low':
$priority = 5;
break;
default:
$priority = 3;
break;
}
}
return parent::setPriority($priority);
}
示例6: priority
/**
* Set the message priority level.
*
* @param int $level
* @return $this
*/
public function priority($level)
{
$this->swift->setPriority($level);
return $this;
}
示例7: send
/**
* Send the mail
* @param string|array $to - mail reciver, can be also as array('john@doe.com' => 'John Doe')
* @param enum(html|text) $format - format of letter (html or text)
* @return boolean
*/
public function send($to, $format = 'text')
{
//include_once LIBPATH
rad_mailtemplate::setCurrentItem($this);
$o = rad_rsmarty::getSmartyObject();
if ($this->getVars()) {
foreach ($this->getVars() as $key => $value) {
$o->assign($key, $value);
}
}
if (!is_file(MAILTEMPLATESPATH . $this->getTemplateName())) {
throw new rad_exception('File "' . MAILTEMPLATESPATH . $this->getTemplateName() . '" not found!');
}
$o->fetch(MAILTEMPLATESPATH . $this->getTemplateName());
$o->clearAllAssign();
if (empty($this->_blocks[$format])) {
throw new rad_exception('Format "' . $format . '" is not declared in file: "' . MAILTEMPLATESPATH . $this->getTemplateName() . '"');
}
if (!empty($this->_mailer)) {
$this->_mailer->setSubject($this->_blocks[$format]['subject']);
if (!empty($this->_blocks[$format]['Cc'])) {
$this->_mailer->setCc($this->_blocks[$format]['Cc']);
}
if (!empty($this->_blocks[$format]['Bcc'])) {
$this->_mailer->setBcc($this->_blocks[$format]['Bcc']);
}
if (!empty($this->_blocks[$format]['headers'])) {
$headers = rad_mailtemplate::parseHeader($this->_blocks[$format]['headers']);
if (!empty($headers)) {
foreach ($headers as $headerName => $headerValue) {
switch (strtolower($headerName)) {
case 'x-priority':
$this->_mailer->setPriority((int) $headerValue);
break;
default:
$this->_mailer->getHeaders()->addTextHeader($headerName, $headerValue);
break;
}
}
}
}
if (!empty($this->_blocks[$format]['body'])) {
$this->_mailer->setBody($this->_blocks[$format]['body'], $format == 'text' ? 'text/plain' : 'text/html');
}
if (!empty($this->_blocks[$format]['from'])) {
$from = explode("\n", str_replace("\r", '', $this->_blocks[$format]['from']));
if (count($from)) {
foreach ($from as $fromString) {
$fromItem = explode('<', $fromString);
if (count($fromItem) > 1) {
$fromName = trim($fromItem[0]);
$fromEmail = trim(str_replace('>', '', $fromItem[1]));
} else {
$fromName = trim($fromItem[0]);
$fromEmail = trim($fromItem[0]);
}
$this->_mailer->setFrom(array($fromEmail => $fromName));
$this->_mailer->setReturnPath($fromEmail);
}
}
}
if (!empty($this->_blocks[$format]['transport'])) {
$transport = explode("\n", str_replace("\r", '', $this->_blocks[$format]['transport']));
if (!empty($transport)) {
$transportParams = array();
foreach ($transport as $transportKey => $transportString) {
$transportString = trim($transportString);
if (!empty($transportString)) {
$transportItem = explode(':', $transportString);
if (count($transportItem) > 1) {
$transportItemKey = trim($transportItem[0]);
unset($transportItem[0]);
$transportItemValue = trim(implode(':', $transportItem));
$transportParams[$transportItemKey] = $transportItemValue;
}
}
}
}
if (empty($transportParams['type'])) {
throw new rad_exception('Error in mailtemplate "' . $this->getTemplateName() . '" at transport block: type of the transport required!');
}
switch (strtolower($transportParams['type'])) {
case 'smtp':
if (empty($transportParams['host']) or empty($transportParams['port']) or empty($transportParams['user']) or !isset($transportParams['password'])) {
throw new rad_exception('Error in mailtemplate "' . $this->getTemplateName() . '" at transport block: Not enouph actual params!');
}
$this->_transportInstance = Swift_SmtpTransport::newInstance($transportParams['host'], $transportParams['port'])->setUsername($transportParams['user'])->setPassword($transportParams['password']);
if (!empty($transportParams['security'])) {
$this->_transportInstance->setEncryption($transportParams['security']);
}
break;
case 'mail':
$this->_transportInstance = Swift_MailTransport::newInstance();
break;
//.........这里部分代码省略.........
示例8: setPriority
/**
* Set the message priority
* This is an integer between 1 (high) and 5 (low)
* @param int The level of priority to use
*/
public function setPriority($priority)
{
$this->message->setPriority($priority);
}
示例9: testPriorityIsAdjustedIfSetTooHighOrLow
/**
* The maximum range for the priority is 1-5.
*/
public function testPriorityIsAdjustedIfSetTooHighOrLow()
{
for ($i = -10; $i < 1; $i++) {
$msg = new Swift_Message();
$msg->setPriority($i);
$this->assertEqual(Swift_Message::PRIORITY_HIGH, $msg->getPriority());
$structure = $msg->build()->readFull();
$this->assertPattern("~X-Priority: 1\r\nX-MSMail-Priority: High~s", $structure);
}
for ($i = 15; $i > 5; $i--) {
$msg = new Swift_Message();
$msg->setPriority($i);
$this->assertEqual(Swift_Message::PRIORITY_LOW, $msg->getPriority());
$structure = $msg->build()->readFull();
$this->assertPattern("~X-Priority: 5\r\nX-MSMail-Priority: Low~s", $structure);
}
}
示例10: sendTo
/**
* Send the e-mail
*
* Friendly name portions (e.g. Admin <admin@example.com>) are allowed. The
* method takes an unlimited number of recipient addresses.
*
* @return boolean True if the e-mail was sent successfully
*/
public function sendTo()
{
$arrRecipients = $this->compileRecipients(func_get_args());
if (empty($arrRecipients)) {
return false;
}
$this->objMessage->setTo($arrRecipients);
$this->objMessage->setCharset($this->strCharset);
$this->objMessage->setPriority($this->intPriority);
// Default subject
if ($this->strSubject == '') {
$this->strSubject = 'No subject';
}
$this->objMessage->setSubject($this->strSubject);
// HTML e-mail
if ($this->strHtml != '') {
// Embed images
if ($this->blnEmbedImages) {
if ($this->strImageDir == '') {
$this->strImageDir = TL_ROOT . '/';
}
$arrMatches = array();
preg_match_all('/(src=|url\\()"([^"]+\\.(jpe?g|png|gif|bmp|tiff?|swf))"/Ui', $this->strHtml, $arrMatches);
$strBase = \Environment::get('base');
// Check for internal images
foreach (array_unique($arrMatches[2]) as $url) {
// Try to remove the base URL
$src = str_replace($strBase, '', $url);
$src = rawurldecode($src);
// see #3713
// Embed the image if the URL is now relative
if (!preg_match('@^https?://@', $src) && file_exists($this->strImageDir . $src)) {
$cid = $this->objMessage->embed(\Swift_EmbeddedFile::fromPath($this->strImageDir . $src));
$this->strHtml = str_replace(array('src="' . $url . '"', 'url("' . $url . '"'), array('src="' . $cid . '"', 'url("' . $cid . '"'), $this->strHtml);
}
}
}
$this->objMessage->setBody($this->strHtml, 'text/html');
}
// Text content
if ($this->strText != '') {
if ($this->strHtml != '') {
$this->objMessage->addPart($this->strText, 'text/plain');
} else {
$this->objMessage->setBody($this->strText, 'text/plain');
}
}
// Add the administrator e-mail as default sender
if ($this->strSender == '') {
list($this->strSenderName, $this->strSender) = $this->splitFriendlyName($GLOBALS['TL_CONFIG']['adminEmail']);
}
// Sender
if ($this->strSenderName != '') {
$this->objMessage->setFrom(array($this->strSender => $this->strSenderName));
} else {
$this->objMessage->setFrom($this->strSender);
}
// Send e-mail
$intSent = self::$objMailer->send($this->objMessage, $this->arrFailures);
// Log failures
if (!empty($this->arrFailures)) {
log_message('E-mail address rejected: ' . implode(', ', $this->arrFailures), $this->strLogFile);
}
// Return if no e-mails have been sent
if ($intSent < 1) {
return false;
}
$arrCc = $this->objMessage->getCc();
$arrBcc = $this->objMessage->getBcc();
// Add a log entry
$strMessage = 'An e-mail has been sent to ' . implode(', ', array_keys($this->objMessage->getTo()));
if (!empty($arrCc)) {
$strMessage .= ', CC to ' . implode(', ', array_keys($arrCc));
}
if (!empty($arrBcc)) {
$strMessage .= ', BCC to ' . implode(', ', array_keys($arrBcc));
}
log_message($strMessage, $this->strLogFile);
return true;
}
示例11: setPriority
/**
* {@inheritdoc}
*
* @return $this|self
*/
public function setPriority($priority) : self
{
$this->message->setPriority($priority);
return $this;
}