本文整理汇总了PHP中Swift_Message::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::getId方法的具体用法?PHP Swift_Message::getId怎么用?PHP Swift_Message::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::getId方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBodySwap
public function testBodySwap()
{
$message1 = new Swift_Message('Test');
$html = Swift_MimePart::newInstance('<html></html>', 'text/html');
$html->getHeaders()->addTextHeader('X-Test-Remove', 'Test-Value');
$html->getHeaders()->addTextHeader('X-Test-Alter', 'Test-Value');
$message1->attach($html);
$source = $message1->toString();
$message2 = clone $message1;
$message2->setSubject('Message2');
foreach ($message2->getChildren() as $child) {
$child->setBody('Test');
$child->getHeaders()->removeAll('X-Test-Remove');
$child->getHeaders()->get('X-Test-Alter')->setValue('Altered');
}
$final = $message1->toString();
if ($source != $final) {
$this->fail("Difference although object cloned \n [" . $source . "]\n[" . $final . "]\n");
}
$final = $message2->toString();
if ($final == $source) {
$this->fail('Two body matches although they should differ' . "\n [" . $source . "]\n[" . $final . "]\n");
}
$id_1 = $message1->getId();
$id_2 = $message2->getId();
$this->assertEquals($id_1, $id_2, 'Message Ids differ');
$id_2 = $message2->generateId();
$this->assertNotEquals($id_1, $id_2, 'Message Ids are the same');
}
示例2: testWritingMessageToByteStreamTwiceUsingAFileAttachment
public function testWritingMessageToByteStreamTwiceUsingAFileAttachment()
{
$message = new Swift_Message();
$message->setSubject('test subject');
$message->setTo('user@domain.tld');
$message->setCc('other@domain.tld');
$message->setFrom('user@domain.tld');
$attachment = Swift_Attachment::fromPath($this->_attFile);
$message->attach($attachment);
$message->setBody('HTML part', 'text/html');
$id = $message->getId();
$date = preg_quote(date('r', $message->getDate()), '~');
$boundary = $message->getBoundary();
$streamA = new Swift_ByteStream_ArrayByteStream();
$streamB = new Swift_ByteStream_ArrayByteStream();
$pattern = '~^' . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: user@domain.tld' . "\r\n" . 'To: user@domain.tld' . "\r\n" . 'Cc: other@domain.tld' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: multipart/mixed;' . "\r\n" . ' boundary="' . $boundary . '"' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'HTML part' . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: ' . $this->_attFileType . '; name=' . $this->_attFileName . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: attachment; filename=' . $this->_attFileName . "\r\n" . "\r\n" . preg_quote(base64_encode(file_get_contents($this->_attFile)), '~') . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D';
$message->toByteStream($streamA);
$message->toByteStream($streamB);
$this->assertPatternInStream($pattern, $streamA);
$this->assertPatternInStream($pattern, $streamB);
}
示例3: send
/**
* Send a message to any number of recipients
* @param Swift_Message The message to send. This does not need to (and shouldn't really) have any of the recipient headers set.
* @param mixed The recipients to send to. Can be a string, Swift_Address or Swift_RecipientList. Note that all addresses apart from Bcc recipients will appear in the message headers
* @param mixed The address to send the message from. Can either be a string or an instance of Swift_Address.
* @return int The number of successful recipients
* @throws Swift_ConnectionException If sending fails for any reason.
*/
public function send(Swift_Message $message, $recipients, $from)
{
Swift_ClassLoader::load("Swift_Message_Encoder");
if (is_string($recipients) && preg_match("/^" . Swift_Message_Encoder::CHEAP_ADDRESS_RE . "\$/", $recipients)) {
$recipients = new Swift_Address($recipients);
} elseif (!$recipients instanceof Swift_AddressContainer) {
throw new Exception("The recipients parameter must either be a valid string email address, " . "an instance of Swift_RecipientList or an instance of Swift_Address.");
}
if (is_string($from) && preg_match("/^" . Swift_Message_Encoder::CHEAP_ADDRESS_RE . "\$/", $from)) {
$from = new Swift_Address($from);
} elseif (!$from instanceof Swift_Address) {
throw new Exception("The sender parameter must either be a valid string email address or " . "an instance of Swift_Address.");
}
$log = Swift_LogContainer::getLog();
if (!$message->getEncoding() && !$this->connection->hasExtension("8BITMIME")) {
$message->setEncoding("QP", true, true);
}
$list = $recipients;
if ($recipients instanceof Swift_Address) {
$list = new Swift_RecipientList();
$list->addTo($recipients);
}
Swift_ClassLoader::load("Swift_Events_SendEvent");
$send_event = new Swift_Events_SendEvent($message, $list, $from, 0);
$this->notifyListeners($send_event, "BeforeSendListener");
$to = $cc = array();
if (!($has_from = $message->getFrom())) {
$message->setFrom($from);
}
if (!($has_return_path = $message->getReturnPath())) {
$message->setReturnPath($from->build(true));
}
if (!($has_reply_to = $message->getReplyTo())) {
$message->setReplyTo($from);
}
if (!$has_reply_to[0]) {
$message->setReplyTo($from->getAddress());
}
if (!($has_message_id = $message->getId())) {
$message->generateId();
}
$this->command("MAIL FROM: " . $message->getReturnPath(true), 250);
$failed = 0;
$sent = 0;
$tmp_sent = 0;
$it = $list->getIterator("to");
while ($it->hasNext()) {
$it->next();
$address = $it->getValue();
$to[] = $address->build();
try {
$this->command("RCPT TO: " . $address->build(true), 250);
$tmp_sent++;
} catch (Swift_BadResponseException $e) {
$failed++;
$send_event->addFailedRecipient($address->getAddress());
if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
$log->addfailedRecipient($address->getAddress());
}
}
}
$it = $list->getIterator("cc");
while ($it->hasNext()) {
$it->next();
$address = $it->getValue();
$cc[] = $address->build();
try {
$this->command("RCPT TO: " . $address->build(true), 250);
$tmp_sent++;
} catch (Swift_BadResponseException $e) {
$failed++;
$send_event->addFailedRecipient($address->getAddress());
if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
$log->addfailedRecipient($address->getAddress());
}
}
}
if ($failed == count($to) + count($cc)) {
$this->reset();
$this->notifyListeners($send_event, "SendListener");
return 0;
}
if (!($has_to = $message->getTo()) && !empty($to)) {
$message->setTo($to);
}
if (!($has_cc = $message->getCc()) && !empty($cc)) {
$message->setCc($cc);
}
$this->command("DATA", 354);
$data = $message->build();
while (false !== ($bytes = $data->read())) {
$this->command($bytes, -1);
//.........这里部分代码省略.........
示例4: 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');
}
示例5: getId
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->message->getId();
}
示例6: testEmbeddedFilesWithMultipartDataCreateMultipartRelatedContentAsAnAlternative
public function testEmbeddedFilesWithMultipartDataCreateMultipartRelatedContentAsAnAlternative()
{
$message = new Swift_Message();
$message->setCharset('utf-8');
$message->setSubject('test subject');
$message->addPart('plain part', 'text/plain');
$image = new Swift_Image('<image data>', 'image.gif', 'image/gif');
$cid = $message->embed($image);
$message->setBody('<img src="' . $cid . '" />', 'text/html');
$message->setTo(array('user@domain.tld' => 'User'));
$message->setFrom(array('other@domain.tld' => 'Other'));
$message->setSender(array('other@domain.tld' => 'Other'));
$id = $message->getId();
$date = preg_quote(date('r', $message->getDate()), '~');
$boundary = $message->getBoundary();
$cidVal = $image->getId();
$this->assertRegExp('~^' . 'Sender: Other <other@domain.tld>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <other@domain.tld>' . "\r\n" . 'To: User <user@domain.tld>' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: multipart/alternative;' . "\r\n" . ' boundary="' . $boundary . '"' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'plain part' . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: multipart/related;' . "\r\n" . ' boundary="(.*?)"' . "\r\n" . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . '<img.*?/>' . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: image/gif; name=image.gif' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: inline; filename=image.gif' . "\r\n" . 'Content-ID: <' . $cidVal . '>' . "\r\n" . "\r\n" . preg_quote(base64_encode('<image data>'), '~') . "\r\n\r\n" . '--\\1--' . "\r\n" . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D', $message->toString());
}
示例7: testHTMLPartAppearsLastEvenWhenAttachmentsAdded
public function testHTMLPartAppearsLastEvenWhenAttachmentsAdded()
{
$message = new Swift_Message();
$message->setCharset('utf-8');
$message->setSubject('test subject');
$message->addPart('plain part', 'text/plain');
$attachment = new Swift_Attachment('<data>', 'image.gif', 'image/gif');
$message->attach($attachment);
$message->setBody('HTML part', 'text/html');
$message->setTo(array('user@domain.tld' => 'User'));
$message->setFrom(array('other@domain.tld' => 'Other'));
$message->setSender(array('other@domain.tld' => 'Other'));
$id = $message->getId();
$date = preg_quote($message->getDate()->format('r'), '~');
$boundary = $message->getBoundary();
$this->assertRegExp('~^' . 'Sender: Other <other@domain.tld>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <other@domain.tld>' . "\r\n" . 'To: User <user@domain.tld>' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: multipart/mixed;' . "\r\n" . ' boundary="' . $boundary . '"' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: multipart/alternative;' . "\r\n" . ' boundary="(.*?)"' . "\r\n" . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'plain part' . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'HTML part' . "\r\n\r\n" . '--\\1--' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: image/gif; name=image.gif' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: attachment; filename=image.gif' . "\r\n" . "\r\n" . preg_quote(base64_encode('<data>'), '~') . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D', $message->toString());
}