/** * @inheritDoc */ public static function fromWrappedMessage(MailWrappedMessage $wrappedMessage = null, $transport = null) { if (!$wrappedMessage instanceof MailWrappedMessage) { throw new MailWrapperSetupException('Not MailWrappedMessage'); } $message = new 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()) { $html = new MimePart($wrappedMessage->getContentHtml()); $html->type = "text/html"; $message->setBody($body); } return $message; }
/** * @param Message $message * @return Message */ public function render(Message $message) { $viewModel = new ViewModel($this->variables); $viewModel->setTemplate($this->template); $helperPluginManager = $this->renderer->getHelperPluginManager(); /** @var HeadTitle $helper */ $helper = $helperPluginManager->get('HeadTitle'); // replace headTitle $headTitle = new HeadTitle(); $headTitle->setAutoEscape(false); $helperPluginManager->setAllowOverride(true); $helperPluginManager->setService('HeadTitle', $headTitle); if (!$message->getBody()) { $message->setBody(new MimeMessage()); } $text = new Part($this->renderer->render($viewModel)); $text->charset = 'UTF-8'; $text->boundary = $message->getBody()->getMime()->boundary(); $text->encoding = Mime::ENCODING_BASE64; $text->type = Mime::TYPE_HTML; $message->getBody()->addPart($text); $message->setSubject($headTitle->renderTitle()); // hack for ZF $message->setBody($message->getBody()); // restore original helper $helperPluginManager->setService('HeadTitle', $helper); return $message; }
public function submitAction() { $result = ""; $contact = $this->params()->fromPost(); $captcha = new Captcha(array('name' => 'captcha', 'wordLen' => 6, 'timeout' => 600)); if ($captcha->isValid($_POST['captcha'], $_POST)) { unset($contact['submit']); $contact = array_filter($contact); if ($contact && is_array($contact)) { $mail = new Mail\Message(); $html = '<p>Contact from Kingsy.co.uk</p><p>=-=-=-=-=-=-=-=-=-=-=-=-=-=</p><p><span></span>From: <span>' . $contact["name"] . '</span></p><p><span></span>Email: <span>' . $contact["email"] . '</span></p><p><span></span>Content<p>' . $contact["content"] . '</p></p>'; $mail->setFrom('*****@*****.**', 'Contact Form - Kingsy.co.uk')->addTo("*****@*****.**")->setSubject('Contacted'); $bodyPart = new MimeMessage(); $bodyMessage = new MimePart($html); $bodyMessage->type = 'text/html'; $bodyPart->setParts(array($bodyMessage)); $mail->setBody($bodyPart); $mail->setEncoding('UTF-8'); try { $transport = new Mail\Transport\Sendmail(); $transport->send($mail); $result = true; } catch (Exception $e) { print_r($e); } } else { $result = false; } } else { $result = false; } return new ViewModel(array('result' => $result)); }
public function indexAction() { $form = $this->getServiceLocator()->get('form.contact'); if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost()->toArray(); $form->setData($post); if ($form->isValid()) { $content = 'Name: ' . $post['name'] . "\n"; $content .= 'Email: ' . $post['email'] . "\n"; $content .= 'Message: ' . "\n" . $post['message']; $message = new Message(); $message->addTo('*****@*****.**'); $message->setSubject('MajorApps website contact'); $message->setBody($content); $message->setFrom('*****@*****.**'); /** @var Smtp $transport */ $transport = $this->getServiceLocator()->get('mail.transport'); $transport->send($message); // Fallback in-case email fails $content = '=======================================' . "\n" . date('Y-m-d H:i:s') . "\n" . $content . "\n" . '=======================================' . "\n"; file_put_contents(__DIR__ . '/../../../../../data/message.txt', $content, FILE_APPEND); $this->flashMessenger()->addSuccessMessage('Message sent successfully'); return $this->redirect()->toRoute('home'); } else { $this->flashMessenger()->addErrorMessage('Message was not sent successfully'); } } return new ViewModel(['form' => $form, 'jargon' => $this->getJargon(), 'features' => $this->getFeatures()]); }
public function send($subject, $text, $to, $from = null) { if (!config('mail.enabled')) { return; } $message = new Message(); $message->setSubject($subject); if ($from) { if (is_array($from)) { $message->setFrom($from[0], $from[1]); } else { $message->setFrom($from); } } $message->addTo($to); $content = '<html><head><title>' . $subject . '</title></head><body>' . $text . '</body></html>'; $html = new Mime\Part($content); $html->setType(Mime\Mime::TYPE_HTML); $html->setCharset('utf-8'); $mimeMessage = new Mime\Message(); $mimeMessage->addPart($html); foreach ($this->attachments as $attachment) { $mimeMessage->addPart($attachment); } $message->setBody($mimeMessage); try { $transport = new SmtpTransport(new SmtpOptions(config('mail.options'))); $transport->send($message); } catch (\Exception $e) { throw $e; } return $this; }
public function sendEmail($from, $to, $cc, $subject, $body, $attachmentFilename) { $message = new Message(); $message->setFrom($from); $message->setTo($to); $message->setCc($cc); $message->setSubject($subject); $mimeMessage = new \Zend\Mime\Message(); $part = new \Zend\Mime\Part($body); $part->setType(Mime::TYPE_TEXT); $part->setCharset('UTF-8'); $mimeMessage->addPart($part); $part = new \Zend\Mime\Part('<p>' . $body . '<p>'); $part->setType(Mime::TYPE_HTML); $part->setCharset('UTF-8'); $mimeMessage->addPart($part); $part = new \Zend\Mime\Part($body); $part->setType(Mime::TYPE_OCTETSTREAM); $part->setEncoding(Mime::ENCODING_BASE64); $part->setFileName($attachmentFilename); $part->setDisposition(Mime::DISPOSITION_ATTACHMENT); $mimeMessage->addPart($part); $message->setBody($mimeMessage); $this->transport->send($message); $this->debugSection('ZendMailer', $subject . ' ' . $from . ' -> ' . $to); }
public function sendMail(MailMessage $message, string $templateName = null, array $params = []) { if (null !== $templateName) { $message->setBody($this->prepareBody($templateName, $params)); } $this->mailer->sendMail($message); }
/** * send * * @param ResetPassword $resetPassword * @param User $user * @param array $mailConfig * * @return mixed */ public function sendRestPasswordEmail(ResetPassword $resetPassword, User $user, $mailConfig) { $toEmail = $user->getEmail(); $fromEmail = $mailConfig['fromEmail']; $fromName = $mailConfig['fromName']; $subject = $mailConfig['subject']; $bodyTemplate = $mailConfig['body']; //Ignore blank emails if (!trim($toEmail)) { return; } $vars = ['name' => '', 'userId' => $user->getId(), 'url' => 'https://' . $_SERVER['HTTP_HOST'] . '/reset-password?fromPasswordResetEmail=1&id=' . $resetPassword->getResetId() . '&key=' . $resetPassword->getHashKey()]; foreach ($vars as $name => $value) { $bodyTemplate = str_replace('__' . $name . '__', $value, $bodyTemplate); // Handle BC $bodyTemplate = str_replace('{' . $name . '}', $value, $bodyTemplate); } try { $html = new MimePart($bodyTemplate); $html->type = "text/html"; $body = new MimeMessage(); $body->setParts([$html]); $message = new Message(); $message->setBody($body)->setFrom($fromEmail, $fromName)->setSubject($subject); foreach (explode(',', $toEmail) as $email) { $message->addTo(trim($email)); } $transport = new \Zend\Mail\Transport\Sendmail(); $transport->send($message); } catch (InvalidArgumentException $e) { // nothing } }
protected function sendEmailAction() { $userTable = $this->getServiceLocator()->get('UserTable'); if (true) { //$this->request->isPost()) { $subject = 'subject'; //$this->request->getPost()->get('subject'); $body = 'body'; //$this->request->getPost()->get('body'); $fromUserId = 1; //$this->user->id; $toUserId = 2; //$this->request->getPost()->get('toUserId'); $fromUser = $userTable->getUser($fromUserId); $toUser = $userTable->getUser($toUserId); $mail = new Mail\Message(); $mail->setFrom($fromUser->email, $fromUser->name); $mail->addTo($toUser->email, $toUser->name); $mail->setSubject($subject); $mail->setBody($body); $transport = new Mail\Transport\Sendmail(); $transport->send($mail); } return true; }
/** * pack tagged array of data to SendMessage format * * * @param Array $mailArray * * return array of data that will be converted to * send message * * @return Array */ public function packData($mailArray) { $mimeMail = new Message(); $textPart = $this->packText($mailArray['text'], $mailArray['header']['content-type']); unset($mailArray['header']['content-type']); $attachmentParts = $this->packAttachments($mailArray['link']); if (count($attachmentParts)) { $mimeMail->addPart($textPart); foreach ($attachmentParts as $part) { $mimeMail->addPart($part); } } else { $mimeMail->addPart($textPart); } $returnMail = new SendMessage(); $returnMail->setBody($mimeMail); foreach ($mailArray['header'] as $header => $value) { switch ($header) { case 'references': if (is_array($value)) { $res = ''; foreach ($value as $reference) { $res .= $reference . ' '; } } elseif (is_string($value)) { $res = $value; } else { continue; } $headers = $returnMail->getHeaders(); $headers->addHeaderLine($header, $res); $returnMail->setHeaders($headers); break; case 'bcc': $returnMail->addBcc($value); break; case 'cc': $returnMail->addCc($value); break; case 'to': $returnMail->addTo($value); break; case 'from': $returnMail->addFrom($value); break; case 'reply-to': $returnMail->addReplyTo($value); break; case 'subject': $returnMail->setSubject($value); break; default: $headers = $returnMail->getHeaders(); $headers->addHeaderLine($header, $value); $returnMail->setHeaders($headers); break; } } return $returnMail; }
/** * Build Message * * @return MailMessage */ public function buildMessage() { // prepare html body $htmlBody = $this->renderer->render($this->viewModel); // prepare text body $textBody = $this->buildTextBody($htmlBody); // prepare subject $subject = $this->buildSubject($htmlBody); // prepare html part $htmlPart = new MimePart($this->buildHtmlHeader() . $htmlBody . $this->buildHtmlFooter()); $htmlPart->type = 'text/html'; // prepare text part $textPart = new MimePart($textBody); $textPart->type = 'text/plain'; // prepare mime message $mailBody = new MimeMessage(); $mailBody->setParts(array($textPart, $htmlPart)); // prepare message $this->message = new MailMessage(); $this->message->setEncoding($this->encoding); $this->message->setFrom($this->senderMail, $this->senderName); $this->message->setSubject($subject); $this->message->setBody($mailBody); // return mailer return $this; }
/** * Add Action * <br/> Responsible for : * <br/>In case Get verb -> Display Add new Book Form * <br/>In case Post verb -> Add new book details into Database * After Submit Book Form * @return ViewModel add view */ public function addAction() { $form = new BookForm(); $form->get('submit')->setValue('Add'); // Another way to set Submit button value // $form->get('submit')->setAttribute('value', 'Add'); $request = $this->getRequest(); // Check If request is Post verb if ($request->isPost()) { $book = new Book(); $form->setInputFilter($book->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $book->exchangeArray($form->getData()); $this->getBookTable()->saveBook($book); //Send an email when a new book Was Added $mail = new Mail\Message(); $mail->setBody('A new Book called ' . $book->title . ' has been added.'); $mail->setFrom('*****@*****.**', 'Zend course'); $mail->addTo('*****@*****.**', 'Ahmed Hamdy'); $mail->setSubject('A Book was Added'); $transport = new Mail\Transport\Sendmail(); $transport->send($mail); } // redirect to list of books return $this->redirect()->toRoute('book'); } return new ViewModel(array('form' => $form)); }
/** * Send email to contacts, insert message into db, log operation */ public function sendAction() { $form = new ContactsForm(); $request = $this->getRequest(); if ($request->isPost()) { $mainLayout = $this->initializeFrontendWebsite(); $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $inputFilter = new ContactsFormInputFilter(); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $inputFilter->exchangeArray($form->getData()); $formData = $request->getPost(); $configurations = $this->layout()->getVariable('configurations'); $mail = new Mail\Message(); $mail->setFrom($configurations['emailnoreply'], $formData->nome . ' ' . $formData->cognome); $mail->addTo($configurations['emailcontact'], $configurations['sitename']); $mail->setSubject('Nuovo messaggio dal sito ' . $configurations['sitename']); $mail->setBody("Nome e cognome: \n " . $formData->nome . " " . $formData->cognome . " Email: " . $formData->email . "\n Messaggio: " . $formData->messaggio); $transport = new Mail\Transport\Sendmail(); $transport->send($mail); $helper = new ContactsControllerHelper(); $helper->setConnection($em->getConnection()); $helper->insert($inputFilter); $this->layout()->setVariables(array('configuraitions' => $configurations, 'homepage' => !empty($homePageElements) ? $homePageElements : null, 'templatePartial' => 'contatti/ok.phtml')); $this->layout()->setTemplate($mainLayout); } else { foreach ($form->getInputFilter()->getInvalidInput() as $invalidInput) { var_dump($form->getMessages()); } exit; } } }
/** * Send contact mail * @param $controller * @param $data */ public static function sendContactMail($controller, $data) { // prepare html content $comments = nl2br($data['comments']); // line break $content = ''; $content .= '<table>'; $content .= '<tbody>'; $content .= "<tr><td>First Name:</td><td>{$data['firstName']}</td></tr>"; $content .= "<tr><td>Last Name:</td><td>{$data['lastName']}</td></tr>"; $content .= "<tr><td>Phone Number:</td><td>{$data['phone']}</td></tr>"; $content .= "<tr><td>Email:</td><td>{$data['email']}</td></tr>"; $content .= "<tr><td>Company:</td><td>{$data['company']}</td></tr>"; $content .= "<tr><td>Job Title:</td><td>{$data['jobTitle']}</td></tr>"; $content .= "<tr><td>Comments:</td><td>{$comments}</td></tr>"; $content .= '</tbody>'; $content .= '</table>'; $html = new MimePart($content); $html->type = "text/html"; $body = new MimeMessage(); $body->setParts(array($html)); $message = new Message(); $message->setBody($body); // subject $subject = 'Contact from Papertask'; $message->setSubject($subject); // get transport $transport = $controller->getServiceLocator()->get('mail.transport'); $message->addTo($transport->mailOptions['contact']); $message->addFrom($transport->mailOptions['contact']); $transport->send($message); }
/** * Sends award certificate * * @param \User\Model\Entity\User $user * @param array $exam * @param \ZendPdf\Document $pdf */ public function sendCertificate($user, $exam, $pdf) { $translator = $this->services->get('translator'); $mail = new Message(); $mail->addTo($user->getEmail(), $user->getName()); $text = 'You are genius! You answered all the questions correctly. Therefore we are sending you as a gratitude this free award certificate. '; // we create a new mime message $mimeMessage = new MimeMessage(); // create the original body as part $textPart = new MimePart($text); $textPart->type = "text/plain"; // add the pdf document as a second part $pdfPart = new MimePart($pdf->render()); $pdfPart->type = 'application/pdf'; $mimeMessage->setParts(array($textPart, $pdfPart)); $mail->setBody($mimeMessage); $mail->setFrom('*****@*****.**', 'Slavey Karadzhov'); $mail->setSubject($translator->translate('Congratulations: Here is your award certificate')); $transport = $this->services->get('mail-transport'); $transport->send($mail); }
public function addAction() { $form = new BookForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $book = new Book(); $form->setInputFilter($book->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $book->exchangeArray($form->getData()); $this->getBookTable()->saveBook($book); //send email $mail = new Mail\Message(); $mail->setBody('A new book called ' . $book->title . ' has been added.'); $mail->setFrom('*****@*****.**', 'Zend Course'); $mail->addTo('*****@*****.**', 'Myself'); $mail->setSubject('A Book was added'); $transport = new Mail\Transport\Sendmail(); $transport->send($mail); } //Redirect to books list return $this->redirect()->toRoute('book'); } return array('form' => $form); }
/** * W momencie zapisu lokalizacji do bazy – wysyła się e-mail na stały adres administratora * serwisu z powiadomieniem o dodaniu nowej lokalizacji (nazwa miejsca + link do strony na froncie serwisu) * * @param Entity\Location $location */ public function sendNotificationMail(Entity\Location $location) { /** * dane do wysylanego maila z potwierdzeniem, zdefiniowane w module.config.php */ $config = $this->getServiceManager()->get('Config')['configuration']['location_mail_notification']; /* blokada wysylania maila (do testow) */ if (false === $config['send_notification_mail']) { return false; } $uri = $this->getServiceManager()->get('request')->getUri(); /* @var $uri \Zend\Uri\Http */ $route = $this->getServiceManager()->get('router')->getRoute('location-details'); /* @var $route \Zend\Mvc\Router\Http\Segment */ /** * link do nowej lokalizacji */ $base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost()); $url = $route->assemble(array('id' => $location->getId())); $mailConfig = (object) $config['message_config']; $html = strtr($mailConfig->message, array('%name%' => $location->getName(), '%link%' => $base . $url)); $message = new Mime\Message(); $message->setParts(array((new Mime\Part($html))->setType('text/html'))); $mail = new Mail\Message(); $mail->setBody($message)->setFrom($mailConfig->from_email, $mailConfig->from_name)->addTo($mailConfig->to_email, $mailConfig->to_name)->setSubject($mailConfig->subject); $transport = new Mail\Transport\Smtp(new Mail\Transport\SmtpOptions($config['smtp_config'])); $transport->send($mail); }
public function send($fromAddress, $fromName, $replyToAddress, $replyToName, $toAddress, $toName, $subject, array $mimeParts) { $mail = new Message(); if ($fromAddress && $fromName) { $mail->setFrom($fromAddress, $fromName); } else { if ($fromAddress) { $mail->setFrom($fromAddress); } } if ($replyToAddress && $replyToName) { $mail->setReplyTo($replyToAddress, $replyToName); } else { if ($replyToAddress) { $mail->setReplyTo($replyToAddress); } } if ($toAddress && $toName) { $mail->setTo($toAddress, $toName); } else { if ($toAddress) { $mail->setTo($toAddress); } } $mail->setSubject($subject); $mail->setEncoding('utf-8'); $mime = new MimeMessage(); $mime->setParts($mimeParts); $mail->setBody($mime); $this->mailTransport->send($mail); $this->getEventManager()->trigger('send', $mail); }
public function run() { $transport = new SmtpTransport(new SmtpOptions(array('name' => $this->host, 'host' => $this->host, 'port' => $this->port, 'connection_config' => array('username' => $this->sender->getUsername(), 'password' => $this->sender->getPassword())))); if ($this->auth !== null) { $transport->getOptions()->setConnectionClass($this->auth); } $message = new Message(); $message->addFrom($this->sender->getUsername())->setSubject($this->subject); if ($this->bcc) { $message->addBcc($this->recipients); } else { $message->addTo($this->recipients); } $body = new MimeMessage(); if ($this->htmlBody == null) { $text = new MimePart($this->textBody); $text->type = "text/plain"; $body->setParts(array($text)); } else { $html = new MimePart($this->htmlBody); $html->type = "text/html"; $body->setParts(array($html)); } $message->setBody($body); $transport->send($message); }
/** * @param string $subject * @param string $message * @param null|string|array $to * @param null|string|array $cc * @param null|string|array $bcc * @return array */ public function sendMail($subject, $message, $to = null, $cc = null, $bcc = null) { $return = array('success' => true, 'msg' => null); $partBody = new MimePart($this->getPartHeader() . $message . $this->getPartFooter()); $partBody->type = Mime::TYPE_HTML; $partBody->charset = 'utf-8'; $this->body->setParts(array($partBody)); $subject = '[' . APPLICATION_NAME . '] ' . $subject; $mail = new Message(); $mail->addFrom(self::FROM); $mail->setSubject($subject); $mail->setBody($this->body); $mail->setTo($to); if ($cc) { $mail->setCc($cc); } if ($bcc) { $mail->setBcc($bcc); } try { $this->transport->send($mail); } catch (\Exception $e) { $return['success'] = false; $return['msg'] = _('mail.message.not_sent'); //throw new \Exception($e->getMessage(), $e->getCode()); } return $return; }
public function sendCareerMail($sender, $recipient, $subject, $text, $filepath, $candidateName) { $result = false; try { //add attachment $text = new Mime\Part($text); $text->type = Mime\Mime::TYPE_TEXT; $text->charset = 'utf-8'; $fileContent = fopen($filepath, 'r'); $attachment = new Mime\Part($fileContent); $attachment->type = 'application/pdf'; $attachment->filename = $candidateName; $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; // Setting the encoding is recommended for binary data $attachment->encoding = Mime\Mime::ENCODING_BASE64; // then add them to a MIME message $mimeMessage = new Mime\Message(); $mimeMessage->setParts(array($text, $attachment)); // and finally we create the actual email $message = new Message(); $message->setBody($mimeMessage); $message->setFrom($sender); $message->addTo($recipient); $message->setSubject($subject); // Send E-mail message $transport = new Sendmail('-f' . $sender); $transport->send($message); $result = true; } catch (\Exception $e) { $result = false; } // Return status return $result; }
/** * Sends the contact message via email * * @param array $data * @return boolean **/ public function send($data) { $form = $this->getForm(); $form->setData($data); if ($form->isValid()) { $data = $form->getData(); $message = 'Name: ' . $data['name'] . "\r\n"; $message .= 'Email: ' . $data['email'] . "\r\n\r\n"; $message .= $data['comment']; $mail = new Message(); $mail->setBody($message); $mail->setFrom('*****@*****.**'); $mail->addTo('*****@*****.**', 'Rob Keplin'); $mail->setSubject('From robkeplin.com'); $transport = new Sendmail(); try { $transport->send($mail); } catch (RuntimeException $e) { $this->addMessage('The email did not get sent due to sendmail failing. Doh!', self::MSG_ERROR); return false; } $form->setData(array('name' => '', 'email' => '', 'comment' => '')); $this->addMessage('Thanks. Get back to you soon!', self::MSG_NOTICE); return true; } $this->addMessage('Hey, Wait! Something went wrong down there. Please fix the errors and try again.', self::MSG_ERROR); return false; }
protected function sendOfflineMessage($msgSubj, $msgText, $fromUserId, $toUserId) { $userTable = $this->getServiceLocator()->get('UserTable'); $fromUser = $userTable->getById($fromUserId); $toUser = $userTable->getById($toUserId); $mail = new Mail\Message(); $mail->setFrom($fromUser->getEmail(), $fromUser->getName()); $mail->addTo($toUser->getEmail(), $toUser->getName()); $mail->setSubject($msgSubj); $mail->setBody($msgText); $transport = new Mail\Transport\Sendmail(); // $transport = new Mail\Transport\Smtp(); // $options = new Mail\Transport\SmtpOptions(array( // 'name' => 'smtp.gmail.com', // 'host' => 'smtp.gmail.com', // 'connection_class' => 'login', // 'connection_config' => array( // 'ssl' => 'tls', // 'username' => '*****@*****.**', // 'password' => '', // ), // )); // $transport->setOptions($options); $transport->send($mail); return true; }
protected function send() { try { $message = new Message(); $para = array_filter(explode(";", str_replace(array(" ", ","), array("", ";"), $this->dados["para"]))); $message->addTo($para)->addFrom($this->dados["de"]["email"], $this->dados["de"]["nome"])->setSubject($this->dados["assunto"])->addReplyTo($this->dados["replay"]); $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => 'mail.pessoaweb.com.br', 'connection_class' => 'login', 'connection_config' => array('username' => '*****@*****.**', 'password' => 'd1i2s3p4atch'), 'port' => 587)); $html = new MimePart($this->dados["body"]); $html->type = "text/html"; $html->charset = "UTF-8"; $body = new MimeMessage(); if (isset($this->dados["attachment"])) { foreach ($this->dados["attachment"] as $valor) { $attachment = new MimePart($valor["arquivo"]); $attachment->filename = $valor["titulo"]; if (isset($valor["tipo"])) { $attachment->type = $valor["tipo"]; } $attachment->disposition = Mime::DISPOSITION_ATTACHMENT; $attachment->encoding = Mime::ENCODING_BASE64; $body->setParts(array($attachment)); } } $body->addPart($html); $message->setBody($body); $transport->setOptions($options); $transport->send($message); return $transport; } catch (\Exception $e) { debug(array("email" => $e->getMessage()), true); } }
/** * @return string|null */ public function parseBody() { try { $htmlView = $this->renderer->render($this->email->getHtmlLayoutName(), array_merge_recursive(['content' => $this->personaliseMessage($this->email->getMessage())], $this->templateVars)); $textView = $this->renderer->render('plain', array_merge_recursive(['content' => $this->personaliseMessage($this->email->getMessage())], $this->templateVars)); } catch (\Twig_Error_Syntax $e) { $htmlView = $textView = sprintf("Something went wrong with the merge. Error message: %s", $e->getMessage()); } $htmlContent = new MimePart($htmlView); $htmlContent->type = "text/html"; $textContent = new MimePart($textView); $textContent->type = 'text/plain'; $body = new MimeMessage(); $body->setParts(array_merge_recursive($this->attachments, [$htmlContent])); /* * Set specific headers * https://eu.mailjet.com/docs/emails_headers */ //message->getHeaders()->addHeaderLine('X-Mailjet-Campaign', $campaign); //message->getHeaders()->addHeaderLine('X-Mailjet-DeduplicateCampaign', $duplicateCampaign); //message->getHeaders()->addHeaderLine('X-Mailjet-TrackOpen', $trackOpen); //message->getHeaders()->addHeaderLine('X-Mailjet-TrackClick', $trackClick); $this->message->setBody($body); return true; }
private function sendEmail(array $listaEmailTo, array $listaEmailCC, $subject, $msg) { $renderer = $this->getServiceLocator()->get('ViewRenderer'); $content = $renderer->render('email/template', array('msg' => nl2br($msg))); // make a header as html(template) $html = new MimePart($content); $html->type = "text/html"; // make a image inline $image = new MimePart(fopen(__DIR__ . '\\..\\..\\..\\..\\Frota\\view\\email\\fundo_email_checkin.png', 'r')); $image->type = "image/jpeg"; $image->id = "fundo_mail"; $image->disposition = "inline"; // build an email with a text(html) + image(inline) $body = new MimeMessage(); $body->setParts(array($html, $image)); // instance mail $mail = new Mail\Message(); $mail->setBody($body); // will generate our code html from template.phtml $mail->setFrom($this->from['email'], utf8_decode($this->from['nome'])); $mail->addTo($listaEmailTo); //$mail->addCc($listaEmailCC); $mail->setSubject(utf8_decode($subject)); $transport = new Mail\Transport\Smtp($this->options); try { $transport->send($mail); } catch (RuntimeException $exc) { $this->logger->info('Erro ao enviar email para: ' . implode(',', $listaEmailTo) . ' erro: ' . $exc->getMessage() . "\n" . $exc->getTraceAsString()); if ($exc->getMessage() == 'Could not open socket') { throw new Exception('O serviço de e-mail do MPM está indisponível no momento, a mensagem não foi enviada!'); } throw new Exception("Não foi possível enviar a mensagem, ocorreu o seguinte erro: {$exc->getMessage()}!"); } }
protected function convertBodyToMime($text) { $textPart = new Zend\Mime\Part($text); $textPart->setType(Zend\Mime\Mime::TYPE_TEXT); $newBody = new Zend\Mime\Message(); $newBody->addPart($textPart); $this->mail->setBody($newBody); }
/** * Send an e-mail * @param array $recipients An array of the recipients. The key represents the e-mail address, the value is the displayname * @param type $subject The subject of the message * @param type $message The message body * @return void */ public function email($recipients, $subject, $message) { $beehubConfig = \BeeHub::config(); $config = $beehubConfig['email']; $mail = new Mail\Message(); $mail->setBody($message)->addTo($recipients)->setSubject($subject)->setFrom($config['sender_address'], $config['sender_name'])->setEncoding('UTF-8'); $this->emailer->send($mail); }
/** * @expectedException \Mandrill_Invalid_Key */ public function testSendObject() { $message = new Message(); $body = new ToStringObject(); $body->addElement('one')->addElement('two')->addElement('three'); $message->setBody($body); $message->setFrom('*****@*****.**'); $this->mandrill->send($message); }
private function sendMailRegisterConfirm($contactData) { // print_r($contactData);die; $mailer = $this->getServiceLocator()->get('Mailer'); $message = new MailMessage(); $message->setBody('El Mensaje es: ' . $contactData['messaje']); $message->addTo($contactData['email'])->addFrom($contactData['email'])->setSubject('Contacto Solicitado por Doggerout.com por ' . $contactData['name']); $sendMail = $mailer->send($message); return $sendMail; }