本文整理汇总了PHP中Swift_Message::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::getHeaders方法的具体用法?PHP Swift_Message::getHeaders怎么用?PHP Swift_Message::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendMessage
public function sendMessage()
{
$transport = \Swift_SmtpTransport::newInstance($this->mta->address, $this->mta->port);
$swift = \Swift_Mailer::newInstance($transport);
$message = new \Swift_Message();
$headers = $message->getHeaders();
$headers->addTextHeader('X-GreenArrow-MailClass', 'SIGMA_NEWEMKTG_DEVEL');
$message->setSubject($this->data->subject);
$message->setFrom(array($this->data->fromEmail => $this->data->fromName));
$message->setBody($this->html, 'text/html');
$message->addPart($this->plainText, 'text/plain');
$this->logger->log("Crea contenido del correo para enviar");
foreach ($this->data->target as $to) {
$message->setTo($to);
$this->logger->log("Preparandose para enviar mensaje a: {$to}");
$recipients = $swift->send($message, $failures);
if ($recipients) {
\Phalcon\DI::getDefault()->get('logger')->log('Recover Password Message successfully sent!');
} else {
throw new Exception('Error while sending message: ' . $failures);
}
}
}
示例2: createActivity
/**
* Create activity from Swift Message
* @param \Swift_Message $message
* @return EmailActivity
*/
protected function createActivity(\Swift_Message $message)
{
// Creation du doc de trace d'activité avec les données basiques
$from_email = $message->getHeaders()->get('From')->getFieldBody();
$to_email = $message->getHeaders()->get('To')->getFieldBody();
$message_id = $message->getHeaders()->get('Message-ID')->getId();
$subject = $message->getSubject();
$activity = new $this->activity_class();
$activity->setFromEmail($from_email);
$activity->setToEmail($to_email);
$activity->setSubject($subject);
$activity->setMessageId($message_id);
// Récupération du document associé aux relations from_user et to_user
$meta = $this->dm->getClassMetadata($this->activity_class);
$class = $meta->getAssociationTargetClass('from_user');
$repo = $this->dm->getRepository($class);
$user = $repo->findOneByEmail($activity->getFromEmail());
if (!is_null($user)) {
$activity->setFromUser($user);
}
$class = $meta->getAssociationTargetClass('to_user');
$repo = $this->dm->getRepository($class);
$user = $repo->findOneByEmail($activity->getToEmail());
if (!is_null($user)) {
$activity->setToUser($user);
}
return $activity;
}
示例3: 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);
}
示例4: 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);
}
示例5: setHeaders
/**
* Send the message.
*
* @return MailInterface The current instance
*/
protected function setHeaders() : MailInterface
{
$this->swiftMessage->getHeaders()->addTextHeader('X-Mailer', $this->get('X-Mailer'));
$this->swiftMessage->getHeaders()->addTextHeader('X-UCSDMATH-MESSAGE-ID', $this->get('X-UCSDMATH-MESSAGE-ID'));
$this->swiftMessage->getHeaders()->addTextHeader('X-UCSDMATH-APPLICATION', $this->get('X-UCSDMATH-APPLICATION'));
$this->swiftMessage->getHeaders()->addTextHeader('X-UCSDMATH-METHOD', $this->get('X-UCSDMATH-METHOD'));
return $this;
}
示例6: getHeaders
/**
* Get all headers from the message.
*
* @return array
*/
public function getHeaders()
{
$swiftHeaders = $this->message->getHeaders()->listAll();
$headers = [];
foreach ($swiftHeaders as $headerName) {
$headers[$headerName] = $this->getHeader($headerName);
}
return $headers;
}
示例7: testListUnsubscribe
public function testListUnsubscribe()
{
$transport = $this->createTransport();
$message = new \Swift_Message('Test Subject', 'Foo bar');
$message->addTo('to@example.com', 'To Name')->addFrom('from@example.com', 'From Name');
$message->getHeaders()->addTextHeader('List-Unsubscribe', '<mailto:unsubscribe@example.com>');
$mandrillMessage = $transport->getMandrillMessage($message);
$this->assertEquals('<mailto:unsubscribe@example.com>', $mandrillMessage['headers']['List-Unsubscribe']);
$this->assertMessageSendable($message);
}
示例8: testTags
public function testTags()
{
$transport = $this->createTransport();
$message = new \Swift_Message('Test Subject', 'Foo bar');
$message->addTo('to@example.com', 'To Name')->addFrom('from@example.com', 'From Name');
$message->getHeaders()->addTextHeader('X-MC-Tags', 'foo,bar');
$mandrillMessage = $transport->getMandrillMessage($message);
$this->assertEquals('foo', $mandrillMessage['tags'][0]);
$this->assertEquals('bar', $mandrillMessage['tags'][1]);
$this->assertMessageSendable($message);
}
示例9: testUnstructuredHeaderSlashesShouldNotBeEscaped
public function testUnstructuredHeaderSlashesShouldNotBeEscaped()
{
$complicated_header = array('to' => array('email1@example.com', 'email2@example.com', 'email3@example.com', 'email4@example.com', 'email5@example.com'), 'sub' => array('-name-' => array('email1', '"email2"', 'email3\\', 'email4', 'email5'), '-url-' => array('http://google.com', 'http://yahoo.com', 'http://hotmail.com', 'http://aol.com', 'http://facebook.com')));
$json = json_encode($complicated_header);
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $json);
$header = $headers->get('X-SMTPAPI');
$this->assertEquals('Swift_Mime_Headers_UnstructuredHeader', get_class($header));
$this->assertEquals($json, $header->getFieldBody());
}
示例10: parseStream
/**
*
* @param stream $stream
* @param boolean $fillHeaders (default to false)
* @param \Swift_Mime_MimeEntity $message (default to null)
* @return Swift_Mime_MimeEntity|\Swift_Message
*/
public function parseStream($stream, $fillHeaders = false, \Swift_Mime_MimeEntity $message = null)
{
$partHeaders = $this->extractHeaders($stream);
$filteredHeaders = $this->filterHeaders($partHeaders);
$parts = $this->parseParts($stream, $partHeaders);
if (!$message) {
$message = new \Swift_Message();
}
$headers = $this->createHeadersSet($filteredHeaders);
foreach ($headers->getAll() as $name => $header) {
if ($fillHeaders || in_array(strtolower($header->getFieldName()), $this->allowedHeaders)) {
$message->getHeaders()->set($header);
}
}
$this->createMessage($parts, $message);
return $message;
}
示例11: addHeader
/**
* Add a custom text header
*
* @param string $strKey The header name
* @param string $strValue The header value
*/
public function addHeader($strKey, $strValue)
{
$this->objMessage->getHeaders()->addTextHeader($strKey, $strValue);
}
示例12: 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;
//.........这里部分代码省略.........
示例13: 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;
}
示例14: sendEmail
public static function sendEmail($subject, $user_id, $toaddress, $message_text, $message_title, $encoded_html = false)
{
// pulling out just the TO email from a 'Address Name <address@name.com>' style address:
if (strpos($toaddress, '>')) {
preg_match('/([^<]+)\\s<(.*)>/', $toaddress, $matches);
if (count($matches)) {
$toaddress = $matches[2];
}
}
// if the email is bullshit don't try to send to it:
if (!filter_var($toaddress, FILTER_VALIDATE_EMAIL)) {
return false;
}
// TODO: look up user settings for email if user_id is set — allow for multiple SMTP settings
// on a per-user basis in the multi-user system
$email_settings = CASHSystem::getDefaultEmail(true);
if (CASHSystem::getSystemSettings('instancetype') == 'multi' && $user_id) {
$user_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getuser', 'user_id' => $user_id));
$user_details = $user_request->response['payload'];
$setname = false;
if (trim($user_details['display_name'] . '') !== '' && $user_details['display_name'] !== 'Anonymous') {
$setname = $user_details['display_name'];
}
if (!$setname && $user_details['username']) {
$setname = $user_details['username'];
}
if ($setname) {
$fromaddress = $setname . ' <' . $user_details['email_address'] . '>';
} else {
$fromaddress = $user_details['email_address'];
}
} else {
$fromaddress = $email_settings['systememail'];
}
// let's deal with complex versus simple email addresses. if we find '>' present we try
// parsing for name + address from a 'Address Name <address@name.com>' style email:
if (strpos($fromaddress, '>')) {
preg_match('/([^<]+)\\s<(.*)>/', $fromaddress, $matches);
if (count($matches)) {
$from = array($matches[2] => $matches[1]);
} else {
$from = $fromaddress;
}
} else {
$from = $fromaddress;
}
// handle encoding of HTML if specific HTML isn't passed in:
if (!$encoded_html) {
$template = @file_get_contents(CASH_PLATFORM_ROOT . '/settings/defaults/system_email.mustache');
if (file_exists(CASH_PLATFORM_ROOT . '/lib/markdown/markdown.php')) {
include_once CASH_PLATFORM_ROOT . '/lib/markdown/markdown.php';
}
$message_text = Markdown($message_text);
$encoded_html = preg_replace('/(\\shttp:\\/\\/(\\S*))/', '<a href="\\1">\\1</a>', $message_text);
if (!$template) {
$encoded_html .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>' . $message_title . '</title></head><body>' . "<h1>{$message_title}</h1>\n" . "<p>" . $encoded_html . "</p>" . "</body></html>";
} else {
// open up some mustache in here:
include_once CASH_PLATFORM_ROOT . '/lib/mustache/Mustache.php';
$higgins = new Mustache();
$mustache_vars = array('encoded_html' => $encoded_html, 'message_title' => $message_title, 'cdn_url' => defined('CDN_URL') ? CDN_URL : CASH_ADMIN_URL);
$encoded_html = $higgins->render($template, $mustache_vars);
}
}
// deal with SMTP settings later:
$smtp = $email_settings['smtp'];
// include swift mailer
include_once CASH_PLATFORM_ROOT . '/lib/swift/swift_required.php';
if ($smtp) {
// use SMTP settings for goodtimes robust happy mailing
$transport = Swift_SmtpTransport::newInstance($email_settings['smtpserver'], $email_settings['smtpport']);
if ($email_settings['smtpusername']) {
$transport->setUsername($email_settings['smtpusername']);
$transport->setPassword($email_settings['smtppassword']);
}
} else {
// aww shit. use mail() and hope it gets there
$transport = Swift_MailTransport::newInstance();
}
$swift = Swift_Mailer::newInstance($transport);
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($encoded_html, 'text/html');
$message->setTo($toaddress);
$message->addPart($message_text, 'text/plain');
$headers = $message->getHeaders();
$headers->addTextHeader('X-MC-Track', 'opens');
// Mandrill-specific tracking...leave in by defauly, no harm if not Mandrill
if ($recipients = $swift->send($message, $failures)) {
return true;
} else {
return false;
}
}
示例15: mailTo_SendGrid
function mailTo_SendGrid($subject, $from = 'noreply@passinggreen.com', $to, $html, $text, $hdr)
{
global $hdr;
// Your SendGrid account credentials
$username = 'hosting@hgmail.com';
$password = 'magicemail1';
// Create new swift connection and authenticate
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 465, 'ssl');
$transport->setUsername($username);
$transport->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
// add SMTPAPI header to the message
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $hdr->asJSON());
// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
// send out the emails
//return $swift->send($message, $failures);
if ($recipients = $swift->send($message, $failures)) {
// This will let us know how many users received this message
// If we specify the names in the X-SMTPAPI header, then this will always be 1.
//echo 'Message blasted '.$recipients.' users'; // This will break the jSON signup process if turned on.
} else {
// something went wrong =(
print_r($failures);
}
}