本文整理汇总了PHP中Swift_Message::toString方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::toString方法的具体用法?PHP Swift_Message::toString怎么用?PHP Swift_Message::toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::toString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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));
}
示例3: toString
/**
* Get this message as a complete string.
*
* @return string
*/
public function toString()
{
$this->saveMessage();
$this->doSign();
$string = parent::toString();
$this->restoreMessage();
return $string;
}
示例4: 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);
}
示例5: getPart
/**
* TODO Better support of RFC1341
*
* @param \Swift_Message $message
* @param string $contentType
*
* @return null
*/
protected function getPart(\Swift_Message $message, $contentType)
{
$dumpedMessage = explode("\r\n", $message->toString());
// save current line (relative to $key)
foreach ($dumpedMessage as $key => $value) {
if ($value != "Content-Type: " . $contentType) {
continue;
}
$index = 1;
// Detect Transfert Encoding
$encoding = null;
while (true) {
if (strpos($dumpedMessage[$key + $index], "Content-Transfer-Encoding:") !== false) {
$line = trim($dumpedMessage[$key + $index]);
$encoding = substr($line, 27, strlen($line) - 27);
$encoding = explode(';', $encoding);
$encoding = strtolower($encoding[0]);
break;
}
if ($dumpedMessage[$key + $index] == "") {
$index++;
break;
}
$index++;
}
// Skip others header, to get content
while ($dumpedMessage[$key + $index] !== "") {
$index++;
}
$result = [];
// Get all mime/part until boundary is reached
while (isset($dumpedMessage[$key + $index]) && strpos($dumpedMessage[$key + $index], $message->getBoundary()) === false) {
$txt = $dumpedMessage[$key + $index];
// Remove soft break-line
$len = mb_strlen($txt);
if ($encoding == "quoted-printable" && $len > 1 && substr($txt, -1) == "=") {
$txt = substr($txt, 0, $len - 1);
}
$result[] = $txt;
$index++;
}
$resultstr = implode("", $result);
switch ($encoding) {
case 'quoted-printable':
return quoted_printable_decode($resultstr);
case 'base64':
return base64_decode($resultstr);
default:
return $resultstr;
}
}
return null;
}
示例6:
/**
* Raw email
*/
function __toString()
{
return $this->_message->toString();
}
示例7: retrieve_original_mail_code
private function retrieve_original_mail_code(Swift_Message $message)
{
$complete_mail = "";
try {
$complete_mail = $message->toString();
} catch (Swift_IoException $e) {
$original_body = $message->getBody();
try {
// if io error occurred (images not found tmp folder), try removing images from content to get the content
$reduced_body = preg_replace("/<img[^>]*src=[\"']([^\"']*)[\"']/", "", $original_body);
$message->setBody($reduced_body);
$complete_mail = $message->toString();
$message->setBody($original_body);
} catch (Exception $ex) {
$complete_mail = $original_body;
Logger::log("ERROR SENDING EMAIL: " . $ex->getTraceAsString(), Logger::ERROR);
}
}
return $complete_mail;
}
示例8: getSpamIndexReportForSwiftMessage
/**
* Make an RESTful call to http://spamcheck.postmarkapp.com/filter to test the emails-spam-index.
* See http://spamcheck.postmarkapp.com/doc
* @return array TestResult array('success', 'message', 'curlHttpCode', 'curlError', ['score', 'report'])
*/
public function getSpamIndexReportForSwiftMessage(\Swift_Message $message, $report = 'long')
{
return $this->getSpamIndexReport($message->toString(), $report);
}
示例9: logSwiftmailMessageLong
/**
* Log a Swift_Message object to a text file
*/
public static function logSwiftmailMessageLong(Swift_Message $message)
{
$fd = fopen(PHPWS_SOURCE_DIR . 'logs/email.log', 'a');
fprintf($fd, "=======================\n");
foreach ($message->getFrom() as $address => $name) {
fprintf($fd, "From: %s <%s>\n", $name, $address);
}
foreach ($message->getTo() as $address => $name) {
fprintf($fd, "To: %s <%s>\n", $name, $address);
}
$cc = $message->getCc();
if (!empty($cc)) {
foreach ($cc() as $address => $name) {
fprintf($fd, "Cc: %s <%s>\n", $name, $address);
}
}
$bcc = $message->getBcc();
if (!empty($bcc)) {
foreach ($bcc as $address => $name) {
fprintf($fd, "Bcc: %s <%s>\n", $name, $address);
}
}
fprintf($fd, "Sender: %s\n", $message->getSender());
fprintf($fd, "Subject: %s\n", $message->getSubject());
fprintf($fd, "Date: %s\n", date('Y-m-d H:i:s'));
fprintf($fd, "Content: \n");
fprintf($fd, "%s\n\n", $message->toString());
}
示例10: toString
/**
* @return string
*/
public function toString() : string
{
return $this->message->toString();
}
示例11: createFromSwiftMessage
/**
* Creates a DmSentMail from a Swift_Message
* @param Swift_Message $message
* @return DmSentMail
*/
public function createFromSwiftMessage(Swift_Message $message)
{
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' => $message->getReplyTo(), 'sender_email' => $message->getSender(), 'debug_string' => $message->toString()));
}
示例12: testCreatesPreviewFiles
public function testCreatesPreviewFiles()
{
$message = new Swift_Message('Foo subject', '<html>Body</html>', 'text/html');
$message->setFrom('myself@example.com', 'Jack Black');
$message->setTo('me@example.com');
$files = m::mock('Illuminate\\Filesystem\\Filesystem');
$transport = new PreviewTransport($files, 'framework/emails');
$files->shouldReceive('exists')->once()->with('framework/emails')->andReturn(true);
$files->shouldReceive('files')->once()->with('framework/emails')->andReturn([]);
$files->shouldReceive('put')->with('framework/emails/' . $message->getDate() . '_me_at_example_com_foo_subject.html', m::any());
$files->shouldReceive('put')->with('framework/emails/' . $message->getDate() . '_me_at_example_com_foo_subject.eml', $message->toString());
$transport->send($message);
}
示例13: 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());
}
示例14: 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());
}