/** * Update an existing template * * @link https://mandrillapp.com/api/docs/templates.html#method=update * @param string $name * @param Address $address * @param string $subject * @param string $html * @param string $text * @param array $labels * @return array * @throws Exception\RuntimeException If there are more than 10 template labels */ public function updateTemplate($name, Address $address = null, $subject = '', $html = '', $text = '', array $labels = array()) { if (count($labels) > 10) { throw new Exception\RuntimeException('Mandrill only supports up to 10 template labels'); } $parameters = array('name' => $name, 'from_email' => $address !== null ? $address->getEmail() : '', 'from_name' => $address !== null ? $address->getName() : '', 'subject' => $subject, 'code' => $html, 'text' => $text, 'labels' => $labels); $response = $this->prepareHttpClient('/templates/update.json', $parameters)->send(); return $this->parseResponse($response); }
public function testToStringCreatesStringRepresentation() { $address = new Address('*****@*****.**', 'ZF DevTeam'); $this->assertEquals('ZF DevTeam <*****@*****.**>', $address->toString()); }
/** * Send an email message. * * @param string|Address|AddressList $to Recipient email address (or * delimited list) * @param string|Address $from Sender name and email address * @param string $subject Subject line for message * @param string $body Message body * @param string $cc CC recipient (null for none) * * @throws MailException * @return void */ public function send($to, $from, $subject, $body, $cc = null) { if ($to instanceof AddressList) { $recipients = $to; } else { if ($to instanceof Address) { $recipients = new AddressList(); $recipients->add($to); } else { $recipients = $this->stringToAddressList($to); } } // Validate email addresses: if ($this->maxRecipients > 0 && $this->maxRecipients < count($recipients)) { throw new MailException('Too Many Email Recipients'); } $validator = new \Zend\Validator\EmailAddress(); if (count($recipients) == 0) { throw new MailException('Invalid Recipient Email Address'); } foreach ($recipients as $current) { if (!$validator->isValid($current->getEmail())) { throw new MailException('Invalid Recipient Email Address'); } } $fromEmail = $from instanceof Address ? $from->getEmail() : $from; if (!$validator->isValid($fromEmail)) { throw new MailException('Invalid Sender Email Address'); } // Convert all exceptions thrown by mailer into MailException objects: try { // Send message $message = $this->getNewMessage()->addFrom($from)->addTo($recipients)->setBody($body)->setSubject($subject)->setReplyTo($from); if ($cc !== null) { $message->addCc($cc); } $this->getTransport()->send($message); } catch (\Exception $e) { throw new MailException($e->getMessage()); } }