本文整理汇总了PHP中Swift_Message::addPart方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::addPart方法的具体用法?PHP Swift_Message::addPart怎么用?PHP Swift_Message::addPart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::addPart方法的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: 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;
}
示例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: send
/**
* @param $to
* @param $subject
* @param $body
* @return bool
*/
public function send($to, $subject, $body)
{
include_once "vendor/autoload.php";
date_default_timezone_set("Asia/Colombo");
$this->CI->config->load('send_grid');
$username = $this->CI->config->item('send_grid_username');
$password = $this->CI->config->item('send_grid_password');
$smtp_server = $this->CI->config->item('send_grid_smtp_server');
$smtp_server_port = $this->CI->config->item('send_grid_smtp_server_port');
$sending_address = $this->CI->config->item('email_sender_address');
$sending_name = $this->CI->config->item('email_sender_name');
$from = array($sending_address => $sending_name);
$to = array($to);
$transport = Swift_SmtpTransport::newInstance($smtp_server, $smtp_server_port);
$transport->setUsername($username);
$transport->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($body, 'text/html');
$message->setTo($to);
$message->addPart($body, 'text/plain');
// send message
if ($recipients = $swift->send($message, $failures)) {
return true;
} else {
return false;
}
}
示例5: transformMessage
/**
* Creates a swift message from a ParsedMessage, handles defaults
*
* @param ParsedMessage $parsedMessage
*
* @return \Swift_Message
*/
protected function transformMessage(ParsedMessage $parsedMessage)
{
$message = new \Swift_Message();
if ($from = $parsedMessage->getFrom()) {
$message->setFrom($from);
}
// handle to with defaults
if ($to = $parsedMessage->getTo()) {
$message->setTo($to);
}
// handle cc with defaults
if ($cc = $parsedMessage->getCc()) {
$message->setCc($cc);
}
// handle bcc with defaults
if ($bcc = $parsedMessage->getBcc()) {
$message->setBcc($bcc);
}
// handle reply to with defaults
if ($replyTo = $parsedMessage->getReplyTo()) {
$message->setReplyTo($replyTo);
}
// handle subject with default
if ($subject = $parsedMessage->getSubject()) {
$message->setSubject($subject);
}
// handle body, no default values here
$message->setBody($parsedMessage->getMessageText());
if ($parsedMessage->getMessageHtml()) {
$message->addPart($parsedMessage->getMessageHtml(), 'text/html');
}
return $message;
}
示例6: _mapToSwift
protected function _mapToSwift(SendGrid\Email $mail)
{
$message = new \Swift_Message($mail->getSubject());
/*
* Since we're sending transactional email, we want the message to go to one person at a time, rather
* than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers
* but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be
* ignored anyway.
*/
$message->setTo($mail->to);
$message->setFrom($mail->getFrom(true));
$message->setCc($mail->getCcs());
$message->setBcc($mail->getBccs());
if ($mail->getHtml()) {
$message->setBody($mail->getHtml(), 'text/html');
if ($mail->getText()) {
$message->addPart($mail->getText(), 'text/plain');
}
} else {
$message->setBody($mail->getText(), 'text/plain');
}
if ($replyto = $mail->getReplyTo()) {
$message->setReplyTo($replyto);
}
$attachments = $mail->getAttachments();
//add any attachments that were added
if ($attachments) {
foreach ($attachments as $attachment) {
$message->attach(\Swift_Attachment::fromPath($attachment['file']));
}
}
$message_headers = $message->getHeaders();
$message_headers->addTextHeader("x-smtpapi", $mail->smtpapi->jsonString());
return $message;
}
示例7: sendMailConSendGrid
function sendMailConSendGrid($text, $html, $subject, $from, $to)
{
include_once "lib/php/swift/swift_required.php";
$username = 'unovamx';
$password = 'LanzamientoUnova2012';
// Setup Swift mailer parameters
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername($username);
$transport->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
// send message
$recipients = $swift->send($message, $failures);
if ($recipients <= 0) {
echo "Something went wrong - ";
print_r($failures);
$recipients = 0;
}
return $recipients;
}
示例8: send
/**
* @param string $name
* @param array $context
* @param callable|null $callback a callback to modify the mail before it is sent.
*/
public function send($name, array $context = [], callable $callback = null)
{
$template = $this->twig->loadTemplate($name);
$blocks = [];
foreach (['from', 'from_name', 'to', 'to_name', 'subject', 'body_txt', 'body_html'] as $blockName) {
$rendered = $this->renderBlock($template, $blockName, $context);
if ($rendered) {
$blocks[$blockName] = $rendered;
}
}
$blocks = array_merge($context, $blocks);
$mail = new \Swift_Message();
$mail->setSubject($blocks['subject']);
$mail->setFrom(isset($blocks['from_name']) ? [$blocks['from'] => $blocks['from_name']] : $blocks['from']);
if (isset($blocks['to'])) {
$mail->setTo(isset($blocks['to_name']) ? [$blocks['to'] => $blocks['to_name']] : $blocks['to']);
}
if (isset($blocks['body_txt']) && isset($blocks['body_html'])) {
$mail->setBody($blocks['body_txt']);
$mail->addPart($blocks['body_html'], 'text/html');
} elseif (isset($blocks['body_txt'])) {
$mail->setBody($blocks['body_txt']);
} elseif (isset($blocks['body_html'])) {
$mail->setBody($blocks['body_html'], 'text/html');
}
if ($callback) {
$callback($mail);
}
$this->mailer->send($mail);
}
示例9: sendEmail
public function sendEmail($recipient_name, $recipient_email, $subject, $body)
{
//$subject = 'Hello from Mandrill, PHP!';
$from = array($this::SENDER_EMAIL => $this::SENDER_NAME);
$to = array($recipient_email => $recipient_name);
//$text = "Mandrill speaks plaintext";
//$html = "<em>Mandrill speaks <strong>HTML</strong></em>";
$transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
$transport->setUsername($this::MANDRILL_USERNAME);
$transport->setPassword($this::MANDRILL_PASSWORD);
$swift = Swift_Mailer::newInstance($transport);
$message = new Swift_Message($subject);
$message->setFrom($from);
//$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($body, 'text/plain');
$failures = '';
if ($recipients = $swift->send($message, $failures)) {
echo 'Message successfully sent!';
return true;
} else {
echo "There was an error:\n";
print_r($failures);
return false;
}
}
示例10: addPart
public function addPart($body, $contentType = null, $charset = null)
{
if ($contentType === 'text/html') {
$this->_html = (string) $body;
} elseif ($contentType === 'text/plain') {
$this->_text = (string) $body;
}
return parent::addPart($body, $contentType, $charset);
}
示例11: sendEmail
/**
* Sends an email
* @param \Swift_Message $message An email message
* @param string $content The message body in HTML
* @return int The number of recipients the message was delivered to
*/
protected static function sendEmail(\Swift_Message $message, $content)
{
// Lazy mailer instantiation
if (!self::$mailer) {
self::$mailer = \Swift_Mailer::newInstance(\Swift_SmtpTransport::newInstance(SMTP_SERVER, SMTP_SERVER_PORT));
}
$message->setBody($content, 'text/html', 'utf-8');
$message->addPart(\Html2Text\Html2Text::convert(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')), 'text/plain', 'utf-8');
return self::$mailer->send($message);
}
示例12: testMultipartHtmlFirst
public function testMultipartHtmlFirst()
{
$transport = $this->createTransport();
$message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
$message->addPart('Foo bar', 'text/plain')->addTo('to@example.com', 'To Name')->addFrom('from@example.com', 'From Name');
$mandrillMessage = $transport->getMandrillMessage($message);
$this->assertEquals('Foo bar', $mandrillMessage['text'], 'Multipart email should contain plaintext message');
$this->assertEquals('<p>Foo bar</p>', $mandrillMessage['html'], 'Multipart email should contain HTML message');
$this->assertMessageSendable($message);
}
示例13: preparedMessage
private function preparedMessage($email, $parameters)
{
$message = new \Swift_Message();
$message->setTo($email);
$message->setFrom($this->template->renderBlock('from', $parameters), $this->template->renderBlock('from_name', $parameters));
$message->setSubject($this->template->renderBlock('subject', $parameters));
$message->setBody($this->template->renderBlock('body_text', $parameters));
$message->addPart($this->template->renderBlock('body_html', $parameters), 'text/html');
return $message;
}
示例14: _mapToSwift
protected function _mapToSwift(Mail $mail)
{
$message = new \Swift_Message($mail->getSubject());
/*
* Since we're sending transactional email, we want the message to go to one person at a time, rather
* than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers
* but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be
* ignored anyway.
*/
$message->setTo($mail->getFrom());
$message->setFrom($mail->getFrom(true));
$message->setCc($mail->getCcs());
$message->setBcc($mail->getBccs());
if ($mail->getHtml()) {
$message->setBody($mail->getHtml(), 'text/html');
if ($mail->getText()) {
$message->addPart($mail->getText(), 'text/plain');
}
} else {
$message->setBody($mail->getText(), 'text/plain');
}
if ($replyto = $mail->getReplyTo()) {
$message->setReplyTo($replyto);
}
// determine whether or not we can use SMTP recipients (non header based)
if ($mail->useHeaders()) {
//send header based email
$message->setTo($mail->getFrom());
//here we'll add the recipients list to the headers
$headers = $mail->getHeaders();
$headers['to'] = $mail->getTos();
$mail->setHeaders($headers);
} else {
$recipients = array();
foreach ($mail->getTos() as $recipient) {
if (preg_match("/(.*)<(.*)>/", $recipient, $results)) {
$recipients[trim($results[2])] = trim($results[1]);
} else {
$recipients[] = $recipient;
}
}
$message->setTo($recipients);
}
$attachments = $mail->getAttachments();
//add any attachments that were added
if ($attachments) {
foreach ($attachments as $attachment) {
$message->attach(\Swift_Attachment::fromPath($attachment['file']));
}
}
//add all the headers
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $mail->getHeadersJson());
return $message;
}
示例15: testTransportSendMultipart
public function testTransportSendMultipart()
{
$container = $this->createContainer();
/** @var MandrillTransport $transport */
$transport = $container->get('swiftmailer.mailer.transport.accord_mandrill');
$message = new \Swift_Message('TEST SUBJECT', '<p>test html body<p>', 'text/html');
$message->setTo('to@example.com');
$message->setFrom('from@example.com');
$message->addPart('test text body', 'text/plain');
$result = $transport->send($message);
$this->assertEquals(1, $result, 'One multipart message should have been sent to Mandrill');
}