本文整理汇总了PHP中Swift_Message::getTo方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::getTo方法的具体用法?PHP Swift_Message::getTo怎么用?PHP Swift_Message::getTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::getTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: sendSwiftMessage
/**
* Send a Swift Message instance.
*
* @param \Swift_Message $message
* @return int
*/
protected function sendSwiftMessage($message)
{
$from = $message->getFrom();
if (empty($from)) {
list($sender_addr, $sender_name) = $this->sender_addr;
empty($sender_addr) or $message->setFrom($sender_addr, $sender_name);
}
list($log_addr, $log_name) = $this->log_addr;
empty($log_addr) or $message->setBcc($log_addr, $log_name);
$to = $message->getTo();
empty($to) or $to = key($to);
/*
* Set custom headers for tracking
*/
$headers = $message->getHeaders();
$headers->addTextHeader('X-Site-ID', $this->x_site_id);
$headers->addTextHeader('X-User-ID', base64_encode($to));
/*
* Set to address based on environment
*/
if (strcasecmp($this->environment, 'production') != 0) {
list($dev_addr, $dev_name) = $this->developer_addr;
$message->setTo($dev_addr, $dev_name);
}
/*
* Set return path.
*/
if ($this->return_path) {
$return_path = $this->generateReturnPathEmail(key($message->getTo()));
$message->setReturnPath($return_path);
}
parent::sendSwiftMessage($message);
}
示例3: renderMessageInformation
protected function renderMessageInformation(Swift_Message $message)
{
static $i = 0;
$i++;
$to = null === $message->getTo() ? '' : implode(', ', array_keys($message->getTo()));
$html = array();
$html[] = sprintf('<h3>%s (to: %s) %s</h3>', $message->getSubject(), $to, $this->getToggler('sfWebDebugMailTemplate' . $i));
$html[] = '<div id="sfWebDebugMailTemplate' . $i . '" style="display:' . (1 == $i ? 'block' : 'none') . '">';
$html[] = '<pre>' . htmlentities($message->toString(), ENT_QUOTES, $message->getCharset()) . '</pre>';
$html[] = '</div>';
return implode("\n", $html);
}
示例4: send
public function send(\Swift_Message $message)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $this->host);
//不同于登录SendCloud站点的帐号,您需要登录后台创建发信子帐号,使用子帐号和密码才可以进行邮件的发送。
$from = $message->getFrom();
$to = '';
foreach ($message->getTo() as $_mail => $_toName) {
if ($to .= '') {
$to .= ';';
}
$to .= $_mail;
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('api_user' => $this->username, 'api_key' => $this->password, 'from' => $this->username, 'fromname' => is_array($from) ? current($from) : $from, 'to' => $to, 'subject' => $message->getSubject(), 'html' => $message->getBody())));
$result = curl_exec($ch);
//请求失败
if ($result === false) {
throw new \Exception(curl_error($ch));
}
curl_close($ch);
$ret = json_decode($result);
p($result);
if ($ret->message != 'success') {
throw new \Exception($result);
}
return $result;
}
示例5: createFromSwiftMessage
/**
* Creates a DmSentMail from a Swift_Message
* @param Swift_Message $message
* @return DmSentMail
*/
public function createFromSwiftMessage(Swift_Message $message)
{
$debug = $message->toString();
if ($attachementPosition = strpos($debug, 'attachment; filename=')) {
$debug = substr($debug, 0, $attachementPosition);
}
return $this->create(array('subject' => $message->getSubject(), 'body' => $message->getBody(), 'from_email' => implode(', ', array_keys((array) $message->getFrom())), 'to_email' => implode(', ', array_keys((array) $message->getTo())), 'cc_email' => implode(', ', array_keys((array) $message->getCC())), 'bcc_email' => implode(', ', array_keys((array) $message->getBCC())), 'reply_to_email' => implode(', ', array_keys((array) $message->getReplyTo())), 'sender_email' => implode(', ', array_keys((array) $message->getSender())), 'debug_string' => $debug));
}
示例6: getTo
/**
* Returns a list of defined recipients.
*
* @return array
*/
public function getTo()
{
$recipients = [];
foreach ($this->message->getTo() as $email => $name) {
$recipients[] = new Email($email, $name);
}
return $recipients;
}
示例7: messageToArray
/**
* Converts \Swift_Message into associative array
*
* @param array $search If the mailer requires tokens in another format than Mautic's, pass array of Mautic tokens to replace
* @param array $replace If the mailer requires tokens in another format than Mautic's, pass array of replacement tokens
*
* @return array|\Swift_Message
*/
protected function messageToArray($search = array(), $replace = array())
{
if (!empty($search)) {
MailHelper::searchReplaceTokens($search, $replace, $this->message);
}
$from = $this->message->getFrom();
$fromEmail = current(array_keys($from));
$fromName = $from[$fromEmail];
$message = array('html' => $this->message->getBody(), 'text' => MailHelper::getPlainTextFromMessage($this->message), 'subject' => $this->message->getSubject(), 'from' => array('name' => $fromName, 'email' => $fromEmail));
// Generate the recipients
$message['recipients'] = array('to' => array(), 'cc' => array(), 'bcc' => array());
$to = $this->message->getTo();
foreach ($to as $email => $name) {
$message['recipients']['to'][$email] = array('email' => $email, 'name' => $name);
}
$cc = $this->message->getCc();
if (!empty($cc)) {
foreach ($cc as $email => $name) {
$message['recipients']['cc'][$email] = array('email' => $email, 'name' => $name);
}
}
$bcc = $this->message->getBcc();
if (!empty($bcc)) {
foreach ($bcc as $email => $name) {
$message['recipients']['bcc'][$email] = array('email' => $email, 'name' => $name);
}
}
$replyTo = $this->message->getReplyTo();
if (!empty($replyTo)) {
foreach ($replyTo as $email => $name) {
$message['replyTo'] = array('email' => $email, 'name' => $name);
}
}
$returnPath = $this->message->getReturnPath();
if (!empty($returnPath)) {
$message['returnPath'] = $returnPath;
}
// Attachments
$children = $this->message->getChildren();
$attachments = array();
foreach ($children as $child) {
if ($child instanceof \Swift_Attachment) {
$attachments[] = array('type' => $child->getContentType(), 'name' => $child->getFilename(), 'content' => $child->getEncoder()->encodeString($child->getBody()));
}
}
$message['attachments'] = $attachments;
return $message;
}
示例8: assertSendCalled
/**
* @param string $templateName
* @param array $templateParams
* @param \Swift_Message $expectedMessage
* @param string $emailType
*/
protected function assertSendCalled($templateName, array $templateParams, \Swift_Message $expectedMessage, $emailType = 'txt')
{
$this->emailTemplate->expects($this->once())->method('getType')->willReturn($emailType);
$this->objectRepository->expects($this->once())->method('findOneBy')->with(['name' => $templateName])->willReturn($this->emailTemplate);
$this->renderer->expects($this->once())->method('compileMessage')->with($this->emailTemplate, $templateParams)->willReturn([$expectedMessage->getSubject(), $expectedMessage->getBody()]);
$to = $expectedMessage->getTo();
$toKeys = array_keys($to);
$this->emailHolderHelper->expects($this->once())->method('getEmail')->with($this->isInstanceOf('Oro\\Bundle\\UserBundle\\Entity\\UserInterface'))->willReturn(array_shift($toKeys));
$this->mailer->expects($this->once())->method('send')->with($this->callback(function (\Swift_Message $actualMessage) use($expectedMessage) {
$this->assertEquals($expectedMessage->getSubject(), $actualMessage->getSubject());
$this->assertEquals($expectedMessage->getFrom(), $actualMessage->getFrom());
$this->assertEquals($expectedMessage->getTo(), $actualMessage->getTo());
$this->assertEquals($expectedMessage->getBody(), $actualMessage->getBody());
$this->assertEquals($expectedMessage->getContentType(), $actualMessage->getContentType());
return true;
}));
}
示例9: messageToArray
/**
* Converts \Swift_Message into associative array.
*
* @param array $search If the mailer requires tokens in another format than Mautic's, pass array of Mautic tokens to replace
* @param array $replace If the mailer requires tokens in another format than Mautic's, pass array of replacement tokens
* @param bool|false $binaryAttachments True to convert file attachments to binary
*
* @return array|\Swift_Message
*/
protected function messageToArray($search = [], $replace = [], $binaryAttachments = false)
{
if (!empty($search)) {
MailHelper::searchReplaceTokens($search, $replace, $this->message);
}
$from = $this->message->getFrom();
$fromEmail = current(array_keys($from));
$fromName = $from[$fromEmail];
$message = ['html' => $this->message->getBody(), 'text' => MailHelper::getPlainTextFromMessage($this->message), 'subject' => $this->message->getSubject(), 'from' => ['name' => $fromName, 'email' => $fromEmail]];
// Generate the recipients
$message['recipients'] = ['to' => [], 'cc' => [], 'bcc' => []];
$to = $this->message->getTo();
foreach ($to as $email => $name) {
$message['recipients']['to'][$email] = ['email' => $email, 'name' => $name];
}
$cc = $this->message->getCc();
if (!empty($cc)) {
foreach ($cc as $email => $name) {
$message['recipients']['cc'][$email] = ['email' => $email, 'name' => $name];
}
}
$bcc = $this->message->getBcc();
if (!empty($bcc)) {
foreach ($bcc as $email => $name) {
$message['recipients']['bcc'][$email] = ['email' => $email, 'name' => $name];
}
}
$replyTo = $this->message->getReplyTo();
if (!empty($replyTo)) {
foreach ($replyTo as $email => $name) {
$message['replyTo'] = ['email' => $email, 'name' => $name];
}
}
$returnPath = $this->message->getReturnPath();
if (!empty($returnPath)) {
$message['returnPath'] = $returnPath;
}
// Attachments
$children = $this->message->getChildren();
$attachments = [];
foreach ($children as $child) {
if ($child instanceof \Swift_Attachment) {
$attachments[] = ['type' => $child->getContentType(), 'name' => $child->getFilename(), 'content' => $child->getEncoder()->encodeString($child->getBody())];
}
}
if ($binaryAttachments) {
// Convert attachments to binary if applicable
$message['attachments'] = $attachments;
$fileAttachments = $this->getAttachments();
if (!empty($fileAttachments)) {
foreach ($fileAttachments as $attachment) {
if (file_exists($attachment['filePath']) && is_readable($attachment['filePath'])) {
try {
$swiftAttachment = \Swift_Attachment::fromPath($attachment['filePath']);
if (!empty($attachment['fileName'])) {
$swiftAttachment->setFilename($attachment['fileName']);
}
if (!empty($attachment['contentType'])) {
$swiftAttachment->setContentType($attachment['contentType']);
}
if (!empty($attachment['inline'])) {
$swiftAttachment->setDisposition('inline');
}
$message['attachments'][] = ['type' => $swiftAttachment->getContentType(), 'name' => $swiftAttachment->getFilename(), 'content' => $swiftAttachment->getEncoder()->encodeString($swiftAttachment->getBody())];
} catch (\Exception $e) {
error_log($e);
}
}
}
}
} else {
$message['binary_attachments'] = $attachments;
$message['file_attachments'] = $this->getAttachments();
}
$message['headers'] = [];
$headers = $this->message->getHeaders()->getAll();
/** @var \Swift_Mime_Header $header */
foreach ($headers as $header) {
if ($header->getFieldType() == \Swift_Mime_Header::TYPE_TEXT) {
$message['headers'][$header->getFieldName()] = $header->getFieldBodyModel();
}
}
return $message;
}
示例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: logSwiftmailMessage
/**
* PHPWS_Email has a built-in simple logging function. This replicates
* the functionality of that function for SwiftMail.
*/
public static function logSwiftmailMessage(Swift_Message $message)
{
$id = 'id:' . $message->getId();
$from = 'from:' . $message->getSender();
$to = 'to:' . implode(',', array_keys($message->getTo()));
// Optional fields, If the message has them, implode the arrays to simple strings.
$cc = $message->getCc() != null ? 'cc:' . implode(',', array_keys($message->getCc())) : '';
$bcc = $message->getBcc() != null ? 'bcc:' . implode(',', array_keys($message->getBcc())) : '';
$replyto = $message->getReplyTo() != null ? 'reply-to:' . implode(',', array_keys($message->getReplyTo())) : '';
$subject = 'subject:' . $message->getSubject();
$module = 'module:' . PHPWS_Core::getCurrentModule();
$user = 'user:' . (Current_User::isLogged() ? Current_User::getUsername() : '');
PHPWS_Core::log("{$id} {$module} {$user} {$subject} {$from} {$to} {$cc} {$bcc} {$replyto}", 'phpws-mail.log', 'mail');
}
示例12: recipientForbidden
/**
* Checks the email recipients are in domains that are allowed.
* @param Swift_Message $message
* @return bool
*/
protected function recipientForbidden($message)
{
if (!empty(Yii::app()->params['restrict_email_domains'])) {
$to = $message->getTo();
$cc = $message->getCc();
$bcc = $message->getBcc();
$to = $to ? $to : array();
$cc = $cc ? $cc : array();
$bcc = $bcc ? $bcc : array();
$addresses = array_merge($to, $cc, $bcc);
foreach ($addresses as $email => $name) {
$domain = preg_replace('/^.*?@/', '', $email);
if (!in_array($domain, Yii::app()->params['restrict_email_domains'])) {
return true;
}
}
}
return false;
}
示例13: logMessage
/**
* Log that a message was sent.
*
* @param \Swift_Message $message
* @return void
*/
protected function logMessage($message)
{
$emails = implode(', ', array_keys((array) $message->getTo()));
$this->logger->info("Pretending to mail message to: {$emails}");
}
示例14: getTo
/**
* {@inheritdoc}
*/
public function getTo()
{
return $this->message->getTo();
}
示例15: getRecipients
/**
* @return array
*/
public function getRecipients()
{
return $this->message->getTo();
}