public function testSend() { $message = new Swift_Message(); $message->setFrom('*****@*****.**', 'Johnny #5'); $message->setSubject('Is alive!'); $message->addTo('*****@*****.**', 'A. Friend'); $message->addTo('*****@*****.**'); $message->addCc('*****@*****.**'); $message->addCc('*****@*****.**', 'Extra 2'); $message->addBcc('*****@*****.**'); $message->addBcc('*****@*****.**', '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" <*****@*****.**>', 'To' => '"A. Friend" <*****@*****.**>,you+two@example.com', 'Cc' => 'another+1@example.com,"Extra 2" <*****@*****.**>', 'Bcc' => 'another+3@example.com,"Extra 4" <*****@*****.**>', '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); }
/** * @inheritDoc */ public static function fromWrappedMessage(MailWrappedMessage $wrappedMessage = null, $transport = null) { if (!$wrappedMessage instanceof MailWrappedMessage) { throw new MailWrapperSetupException('Not MailWrappedMessage'); } $message = new \Swift_Message(); foreach ($wrappedMessage->getToRecipients() as $address) { $message->addTo($address); } foreach ($wrappedMessage->getCcRecipients() as $address) { $message->addCc($address); } foreach ($wrappedMessage->getBccRecipients() as $address) { $message->addBcc($address); } $message->setReplyTo($wrappedMessage->getReplyTo()); $message->setFrom($wrappedMessage->getFrom()); $message->setSubject($wrappedMessage->getSubject()); if ($wrappedMessage->getContentText()) { $message->setBody($wrappedMessage->getContentText()); } if ($wrappedMessage->getContentHtml()) { $message->setBody($wrappedMessage->getContentHtml(), 'text/html'); } return $message; }
/** * Add email addresses * * @param Swift_Message $mail * @param string $addresses * @param string $field Address field, can be 'to','cc','bcc' */ public function addMailAddresses(&$mail, $addresses, $field = 'to') { if (trim($addresses) == '') { return; } $addrs = explode(';', $addresses); foreach ($addrs as $addr) { //Reformat standar email "name" <email> to name,email $addr = str_replace('" <', '"<', $addr); $addr = str_replace('"<', ',', $addr); $addr = str_replace('"', '', $addr); $addr = str_replace('>', '', $addr); //Fix address format: name,email if (strpos($addr, ',') === false) { $addr = ',' . $addr; } $tmp = explode(',', $addr); switch ($field) { case 'cc': $mail->addCc($tmp[1], $tmp[0]); break; case 'bcc': $mail->addBcc($tmp[1], $tmp[0]); break; default: $mail->addTo($tmp[1], $tmp[0]); break; } } }
/** * {@inheritdoc} * * @return $this|self */ public function addCc($address, $name = null) : self { return $this->message->addCc($address, $name); }
public function addCc(Email $email) { $this->message->addCc($email->email, $email->name); return $this; }
/** * @param \Swift_Message $instance * @param array $from From addresses. An array of (email-address => name) * @param array $to To addresses. An array of (email-address => name) * @param array $cc Cc addresses. An array of (email-address => name) [optional] * @param array $bcc Bcc addresses. An array of (email-address => name) [optional] * @param array $replyTo Reply to addresses. An array of (email-address => name) [optional] */ protected function setupMessageHeaders($instance, $from, $to, $cc = [], $bcc = [], $replyTo = []) { // Add from addresses foreach ($from as $address => $name) { $instance->addFrom($address, $name); } // Add to addresses foreach ($to as $address => $name) { $instance->addTo($address, $name); } // Add cc addresses foreach ($cc as $address => $name) { $instance->addCc($address, $name); } // Add bcc addresses foreach ($bcc as $address => $name) { $instance->addBcc($address, $name); } // Add reply to addresses foreach ($replyTo as $address => $name) { $instance->addReplyTo($address, $name); } }