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; }
/** * Generates the Mail Body */ protected function generateBody() { $message = new Mime\Message(); $text = $this->generateHtml(); $textPart = new Mime\Part($text); $textPart->type = 'text/html'; $textPart->charset = 'UTF-8'; $textPart->disposition = Mime\Mime::DISPOSITION_INLINE; $message->addPart($textPart); if (isset($this->application->getContact()->image) && $this->application->getContact()->getImage()->id) { /* @var $image \Auth\Entity\UserImage */ $image = $this->application->getContact()->getImage(); $part = new Mime\Part($image->getResource()); $part->type = $image->type; $part->encoding = Mime\Mime::ENCODING_BASE64; $part->filename = $image->name; $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; $message->addPart($part); } foreach ($this->application->getAttachments() as $attachment) { /* @var $part \Applications\Entity\Attachment */ $part = new Mime\Part($attachment->getResource()); $part->type = $attachment->type; $part->encoding = Mime\Mime::ENCODING_BASE64; $part->filename = $attachment->name; $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; $message->addPart($part); } $this->setBody($message); }
protected function generateBody() { $message = new Mime\Message(); $text = $this->generateText(); $textPart = new Mime\Part($text); $textPart->type = 'text/plain'; $textPart->charset = 'UTF-8'; $textPart->disposition = Mime\Mime::DISPOSITION_INLINE; $message->addPart($textPart); if (isset($this->application->contact->image) && $this->application->contact->image->id) { $image = $this->application->contact->image; $part = new Mime\Part($image->getResource()); $part->type = $image->type; $part->encoding = Mime\Mime::ENCODING_BASE64; $part->filename = $image->name; $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; $message->addPart($part); } foreach ($this->application->attachments as $attachment) { $part = new Mime\Part($attachment->getResource()); $part->type = $attachment->type; $part->encoding = Mime\Mime::ENCODING_BASE64; $part->filename = $attachment->name; $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; $message->addPart($part); } $this->setBody($message); }
/** * 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; }
/** * @param RenderableMailInterface $mail * * @return Mime\Message */ public function createMessage(RenderableMailInterface $mail) { $content = $this->getMailBody($mail); $message = new Mime\Message(); $message->addPart($content); foreach ($mail->getAttachments() as $name => $file) { $attachment = $this->createAttachment($file, $name); $message->addPart($attachment); } return $message; }
public function generate(TemplateInterface $template) : MimeMessage { $mimeMessage = new MimeMessage(); $textTemplate = $template->getTextTemplate(); if ($textTemplate) { $textMimePart = $this->createTextMimePart($textTemplate, $template->getParams()); $mimeMessage->addPart($textMimePart); } $htmlTemplate = $template->getHtmlTemplate(); if ($htmlTemplate) { $htmlMimePart = $this->createHtmlMimePart($htmlTemplate, $template->getParams()); $mimeMessage->addPart($htmlMimePart); } return $mimeMessage; }
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); } }
public function testInvoke() { $repository = $this->prophesize(RepositoryInterface::class); $listener = new LogSending($repository->reveal()); $event = $this->prophesize(EventInterface::class); $message = $this->prophesize(Message::class); $event->getParam('message')->willReturn($message->reveal()); $template = $this->prophesize(Template::class); $event->getParam('template')->willReturn($template->reveal()); $to = new AddressList(); $to->addFromString('*****@*****.**'); $message->getTo()->willReturn($to); $from = new AddressList(); $from->addFromString('*****@*****.**'); $message->getFrom()->willReturn($from); $message->getSubject()->willReturn('Some subject'); $template->getLayoutId()->willReturn(Template::LAYOUT_DEFAULT); $template->getId()->willReturn(Template::FEEDBACK_ANSWER); $mimeMessage = new MimeMessage(); $mimeMessage->addPart(new \Zend\Mime\Part('some body')); $message->getBody()->willReturn($mimeMessage); $event->getParam('data')->willReturn(['data' => 'x']); $repository->add(Argument::type(MailLogEntry::class)); $listener->__invoke($event->reveal()); }
public function sendMail($mailOptions = array()) { $this->_setMailOptions($mailOptions); $text = new Part($this->mailBody); $text->type = Mime::TYPE_HTML; $mailBodyParts = new MimeMessage(); $mailBodyParts->addPart($text); if (!empty($this->fileNames) && !empty($this->filePaths)) { foreach ($this->filePaths as $key => $filePath) { $file = new Part(file_get_contents($filePath)); $file->encoding = Mime::ENCODING_BASE64; $file->type = finfo_file(finfo_open(), $filePath, FILEINFO_MIME_TYPE); $file->disposition = Mime::DISPOSITION_ATTACHMENT; $file->filename = $this->fileNames[$key]; $mailBodyParts->addPart($file); } } $options = array(); if ($this->useSMTP === false) { $options = new SmtpOptions(array("name" => $this->smtpName, "host" => $this->smtpHost, "port" => $this->smtpPort)); } else { $options = new SmtpOptions(array('name' => $this->smtpName, 'host' => $this->smtpHost, 'port' => $this->smtpPort, 'connection_class' => $this->smtpConnectionClass, 'connection_config' => array('ssl' => $this->smtpSsl, 'username' => $this->smtpUsername, 'password' => $this->smtpPassword))); } $mail = new Message(); $mail->setBody($mailBodyParts); $mail->setFrom($this->mailFrom, $this->mailFromNickName); $mail->addTo($this->mailTo); if (!empty($this->mailCc)) { $mail->addCc($this->mailCc); } if (!empty($this->mailBcc)) { $mail->addBcc($this->mailBcc); } $mail->setSubject($this->mailSubject); $transport = new SmtpTransport(); $transport->setOptions($options); $emailLogInfo = array('email_to' => $this->mailTo, 'email_from' => $this->mailFrom, 'email_body' => $this->mailBody, 'email_subject' => $this->mailSubject, 'sender_type' => $this->mailSenderType); $emailSend = 0; try { $transport->send($mail); $emailSend = 1; } catch (\Exception $e) { $emailLogInfo['email_error'] = $e->getMessage(); throw $e; } return $emailSend; }
private function _setHtmlBody($message = null) { $objMimePart = new MimePart($message); $objMimePart->type = "text/html"; $objMimeMessage = new MimeMessage(); $objMimeMessage->addPart($objMimePart); return $objMimeMessage; }
function sendEmail($to, $subject, $html, $text, $attachments = null) { // HTML part $htmlPart = new Mime\Part($html); $htmlPart->setEncoding(Mime\Mime::ENCODING_QUOTEDPRINTABLE); $htmlPart->setType(Mime\Mime::TYPE_HTML); // Plain text part $textPart = new Mime\Part($text); $textPart->setEncoding(Mime\Mime::ENCODING_QUOTEDPRINTABLE); $textPart->setType(Mime\Mime::TYPE_TEXT); $body = new Mime\Message(); if ($attachments) { // With attachments, we need a multipart/related email. First part // is itself a multipart/alternative message $content = new Mime\Message(); $content->addPart($textPart); $content->addPart($htmlPart); $contentPart = new Mime\Part($content->generateMessage()); $contentPart->setType(Mime\Mime::MULTIPART_ALTERNATIVE); $contentPart->setBoundary($content->getMime()->boundary()); $body->addPart($contentPart); $messageType = Mime\Mime::MULTIPART_RELATED; // Add each attachment foreach ($attachments as $thisAttachment) { $attachment = new Mime\Part($thisAttachment['content']); $attachment->filename = $thisAttachment['filename']; $attachment->type = Mime\Mime::TYPE_OCTETSTREAM; $attachment->encoding = Mime\Mime::ENCODING_BASE64; $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; $body->addPart($attachment); } } else { // No attachments, just add the two textual parts to the body $body->setParts([$textPart, $htmlPart]); $messageType = Mime\Mime::MULTIPART_ALTERNATIVE; } // attach the body to the message and set the content-type $message = new Message(); $message->addTo($to); $message->setEncoding($this->encoding); $message->addFrom($this->fromEmail, $this->fromName); $message->setSubject($subject); $message->setBody($body); $message->getHeaders()->get('content-type')->setType($messageType); $this->getTransport()->send($message); }
public function testMimeMessageBodyRemainsUnchanged() { $part = new Mime\Part('Foo'); $message = new Mime\Message(); $message->addPart($part); $this->mailService->setBody($message); $this->assertTrue($this->mailService->getMessage()->getBody() instanceof Mime\Message); $this->assertEquals($message, $this->mailService->getMessage()->getBody()); }
public function sendMail() { if (false === $this->checkMailValidity()) { throw new \InvalidArgumentException('E-Mail can not be sent as the required fields where not filled in.'); } $mimeBody = new MimeMessage(); if ($this->mailBodyHtml instanceof ViewModel) { $htmlBodyPart = new MimePart($this->createBodyFromViewModel($this->mailBodyHtml)); $htmlBodyPart->charset = $this->mailCharset; $htmlBodyPart->encoding = $this->mailEncoding; $htmlBodyPart->type = 'text/html'; $mimeBody->addPart($htmlBodyPart); } if ($this->mailBodyText instanceof ViewModel) { $textBodyPart = new MimePart($this->createBodyFromViewModel($this->mailBodyText)); $textBodyPart->charset = $this->mailCharset; $textBodyPart->encoding = $this->mailEncoding; $textBodyPart->type = 'text/plain'; $mimeBody->addPart($textBodyPart); } $mailMessage = new MailMessage(); $mailMessage->setBody($mimeBody); $mailMessage->setEncoding($this->mailEncoding); $mailMessage->setFrom($this->mailFrom); $mailMessage->setSender($this->mailFrom); $mailMessage->setTo($this->mailTo); if ($this->mailBcc != '') { $mailMessage->setBcc($this->mailBcc); } if ($this->mailCc != '') { $mailMessage->setCc($this->mailCc); } $mailMessage->setSubject($this->mailSubject); if (2 <= count($mimeBody->getParts())) { $mailMessage->getHeaders()->get('content-type')->setType('multipart/alternative'); } try { $this->transport->send($mailMessage); return true; } catch (\Exception $e) { throw new \Exception($e); } }
/** * @param string $to * @param Template $template * @param array $data * @return Message */ public function assemble($to, Template $template, array $data) { $html = new MimePart($template->getBody($data)); $html->type = "text/html"; $body = new MimeMessage(); $body->addPart($html); $message = new Message(); $message->addFrom($this->config['from-email'], $this->config['from-name'])->addTo($to)->setSubject($template->getSubject())->setBody($body)->setEncoding("UTF-8"); return $message; }
public function send($alias, $to, $from = null, array $data = null) { if (!config('mail.enabled')) { return; } $template = $this->getTemplate($alias); if (!$template) { throw new CoreException('Cannot find template with alias/id: ' . $alias, 404); } if ($data === null) { $data = array(); } $template->setDescription($this->replaceTemplateContent($template->getDescription(), $data)); $template->setName($this->replaceTemplateContent($template->getName(), $data)); $preffix = server_url(base_url()); $content = preg_replace('#background\\: url\\((.*)\\)#', 'background: url(' . $preffix . '$1)', $template->getDescription()); $content = preg_replace('#\\<img src=\\"(.*)\\"#', '<img src="' . $preffix . '$1"', $content); $template->getDescription($content); $message = new Message(); $message->setSubject($template->getName()); if ($from) { $message->setFrom($from); } $message->addTo($to); $content = $template->getDescription(); $content = '<html><head><title>' . $template->getName() . '</title></head><body>' . $template->getDescription() . '</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; }
/** * * @param Message $message * @return ZendMessage */ public static function convert(Message $message) { $mailMessage = new ZendMessage(); $mailMessage->setSubject($message->getSubject()); $mailMessage->setFrom($message->getFrom()); $mailMessage->setTo($message->getTo()); $mailMessage->setCc($message->getCc()); $mailMessage->setBcc($message->getBcc()); $mailMessage->setReplyTo($message->getReplyTo()); $mailMessage->getHeaders()->addHeaders($message->getHeaders()); if ($mailMessage->getSender()) { $mailMessage->setSender($message->getSender()); } if ($message->isMultipart()) { $mimePart = new MimeMessage(); if ($message->getBodyHtml()) { $part = new Part($message->getBodyHtml()); $part->charset = $message->getCharset(); $part->encoding = $message->getEncoding(); $part->type = Mime::TYPE_HTML; $mimePart->addPart($part); } if ($message->getBodyText()) { $part = new Part($message->getBodyText()); $part->charset = $message->getCharset(); $part->encoding = $message->getEncoding(); $part->type = Mime::TYPE_TEXT; $mimePart->addPart($part); } foreach ($message->getAttachments() as $attachment) { $mimePart->addPart($attachment->asMimePart()); } foreach ($message->getParts() as $part) { $mimePart->addPart($part); } $mailMessage->setBody($mimePart); } else { $mailMessage->getHeaders()->addHeaderLine('Content-Type', $message->getContentType()); $mailMessage->setEncoding($message->getEncoding()); $mailMessage->setBody($message->getFilledBody()); } return $mailMessage; }
/** * @param $templateName * @param array $values * @return Message * @throws \Exception */ public function prepareMessage($templateName, $values = array()) { $viewRenderer = $this->getViewRenderer(); $content = $viewRenderer->render('mail/' . $templateName, $values); $html = new Mime\Part($content); $html->setType('text/html'); $body = new Mime\Message(); $body->addPart($html); $message = new Message(); $message->setBody($body); return $message; }
protected function prepareMail(MailMessage $mail, array $viewVariables, $mailTemplateName) { $mailBodyOutput = $this->getRenderContent($viewVariables, $mailTemplateName); $mailBodyOutput = htmlspecialchars_decode(htmlentities($mailBodyOutput, ENT_NOQUOTES, 'UTF-8', false), ENT_NOQUOTES); $content = new MimeMessage(); $part = new Part($mailBodyOutput); $part->type = 'text/html'; $content->addPart($part); $mail->addFrom($this->mailAddress, $this->senderName); $this->addMailTargets($mail); $mail->setEncoding('UTF-8'); $mail->setBody($content); }
public function testGenerate() { $msg = new Mime\Message(); // No Parts $p1 = new Mime\Part('This is a test'); $p2 = new Mime\Part('This is another test'); $msg->addPart($p1); $msg->addPart($p2); $res = $msg->generateMessage(); $mime = $msg->getMime(); $boundary = $mime->boundary(); $p1 = strpos($res, $boundary); // $boundary must appear once for every mime part $this->assertTrue($p1 !== false); if ($p1) { $p2 = strpos($res, $boundary, $p1 + strlen($boundary)); $this->assertTrue($p2 !== false); } // check if the two test messages appear: $this->assertTrue(strpos($res, 'This is a test') !== false); $this->assertTrue(strpos($res, 'This is another test') !== false); // ... more in ZMailTest }
public function sendEmailRecoverPassword($senha, $usuario) { $message = new Message(); $message->addTo($usuario->getEmail())->addFrom('*****@*****.**')->setSubject('Recuperação de Senha'); $transport = new SmtpTransport(); $html = new MimePart('<b>Olá <i>' . $usuario->getNome() . '</i>, uma nova senha foi solicitada no Youselfie. <br> Seguem a baixo suas novas credenciais. <br>' . ' <hr>' . 'E-mail: ' . $usuario->getEmail() . '' . '<br>' . 'Senha: ' . $senha . '</b>'); $html->type = "text/html"; $body = new MimeMessage(); $body->addPart($html); $message->setBody($body); $transport->setOptions($this->getOptions()); $transport->send($message); }
/** * @param $to * @param $from * @param $subject * @param $text */ public static function send($to, $from, $subject, $text) { $message = new Message(); $message->addTo($to)->addFrom($from)->setSubject($subject); $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => MailConstants::HOST, 'connection_class' => 'login', 'connection_config' => array('ssl' => MailConstants::SSL, 'username' => MailConstants::EMAIL, 'password' => MailConstants::PASS), 'port' => MailConstants::PORT)); $html = new MimePart($text); $html->type = "text/html"; $body = new MimeMessage(); $body->addPart($html); $message->setBody($body); $transport->setOptions($options); $transport->send($message); }
/** * @expectedException \Mandrill_Invalid_Key */ public function testSendMultipart() { $message = new Message(); $mime = new MimeMessage(); $part1 = new Part('one'); $part1->type = Mime::TYPE_HTML; $part2 = new Part('two'); $part2->type = Mime::TYPE_TEXT; $fileInfo = new \finfo(FILEINFO_MIME_TYPE); $attachment = __DIR__ . DIRECTORY_SEPARATOR . 'MandrillTest.php'; $part3 = new Part(fopen($attachment, 'r')); $part3->filename = pathinfo($attachment)['basename']; $part3->type = $fileInfo->file($attachment); $part3->encoding = Mime::ENCODING_BASE64; $part3->disposition = Mime::DISPOSITION_ATTACHMENT; $mime->addPart($part1); $mime->addPart($part2); $mime->addPart($part3); $message->setBody($mime); $message->setFrom('*****@*****.**'); $message->addTo('*****@*****.**'); $this->mandrill->send($message); }
public function backupAction() { $log = $this->getServiceLocator()->get('log'); $log->addInfo('备份数据' . "\t" . $this->getRequest()->getServer('REMOTE_ADDR') . "\t" . $this->getRequest()->getHeaders()->get('User-Agent')->getFieldValue()); $dbconf = $this->getServiceLocator()->get('config')['mysqli']; $dump = new \MySQLDump(new \mysqli($dbconf['host'], $dbconf['username'], $dbconf['password'], $dbconf['dbname'])); $filename = date("Y-m-d_H-i-s") . "-db.sql"; $tmpFile = dirname(__FILE__) . "\\" . $filename; $dump->save($tmpFile); $body = new Message(); $part = new Part(); $part->setType(Mime::TYPE_OCTETSTREAM); $part->setContent(file_get_contents($tmpFile)); $part->setDisposition(Mime::DISPOSITION_ATTACHMENT); $part->setFileName($filename); $part2 = new Part(); $part2->setType(Mime::TYPE_TEXT); $part2->setContent('小秋来发数据了'); $body->addPart($part); $body->addPart($part2); $newmessage = new \Zend\Mail\Message(); $newmessage->addTo($this->getServiceLocator()->get('MailOptions')->getMailTo()); $newmessage->addFrom($this->getServiceLocator()->get('MailOptions')->getMailFrom()); $newmessage->setBody($body); $newmessage->setSubject('备份数据'); $transport = new SmtpTransport(); $options = new SmtpOptions($this->getServiceLocator()->get('config')['mail']); $transport->setOptions($options); try { $transport->send($newmessage); echo 1; } catch (\Exception $e) { echo -1; } exit; }
/** * buildMessage * @param string $msgHtml * @param string $msgTxt */ public function buildMessage($msgHtml = '', $msgTxt = '') { //Html part $htmlPart = new MimePart($msgHtml); $htmlPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $htmlPart->type = "text/html; charset=UTF-8"; //text part $textPart = new MimePart($msgTxt); $textPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $textPart->type = "text/plain; charset=UTF-8"; //monatgem do conteúdo da mensagem $this->content = new MimeMessage(); $this->content->addPart($textPart); $this->content->addPart($htmlPart); }
public function sendMail() { $message = new Message(); $message->addTo('*****@*****.**')->addFrom('*****@*****.**')->setSubject('Test send mail using ZF2'); // Setup SMTP transport using LOGIN authentication $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'scarpa1234'), 'port' => 587)); $html = new MimePart('<b>heii, <i>sorry</i>, i\'m going late</b>'); $html->type = "text/html"; $body = new MimeMessage(); $body->addPart($html); $message->setBody($body); $transport->setOptions($options); $transport->send($message); }
private function sendMail($sendTo, $user, $article, $comment) { $message = new Message(); $message->addTo($sendTo)->addFrom('*****@*****.**')->setSubject('Scarpa - New comment in: ' . $article->getTitre()); // Setup SMTP transport using LOGIN authentication $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'scarpa1234'), 'port' => 587)); $messageToSend = '<p>Hello.</p></br><p>The folowing comment have been posted by ' . $user['nom'] . ' on the article: </p>' . $article->getTitre() . '</br><p><i>' . $comment . '</i></p>'; $html = new MimePart($messageToSend); $html->type = "text/html"; $body = new MimeMessage(); $body->addPart($html); $message->setBody($body); $transport->setOptions($options); $transport->send($message); }
/** * Creates a multi-part message body with plain text and HTML (from Markdown) * * @param string $text * @return \Zend\Mime\Message */ public function createMultiPartBody($text) { $plain = new MimePart($text); $plain->type = "text/plain"; $markdown = new Markdown(); $html = new MimePart($markdown->transform($text)); $html->type = "text/html"; $alternatives = new MimeMessage(); $alternatives->setParts(array($plain, $html)); $alternatives->type = "multipart/alternative"; $part = new MimePart($alternatives->generateMessage()); $part->type = "multipart/alternative;\n boundary=\"" . $alternatives->getMime()->boundary() . "\""; $body = new MimeMessage(); $body->addPart($part); return $body; }
public function SendMailSmtp($to, $subject, $body, $tokenKeyValues = array()) { $body = $this->tokenReplace($tokenKeyValues, $body); $subject = $this->tokenReplace($tokenKeyValues, $subject); $message = new Message(); //$message->addTo("*****@*****.**") $message->addTo($to)->addFrom('*****@*****.**')->setSubject($subject); // Setup SMTP transport using LOGIN authentication $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'narwaria'), 'port' => 587)); $html = new MimePart($body); $html->type = "text/html"; $body = new MimeMessage(); $body->addPart($html); $message->setBody($body); $transport->setOptions($options); $transport->send($message); }
private function sendMail($data) { $message = new Message(); $message->addTo('*****@*****.**')->addFrom('*****@*****.**')->setSubject('Сообщение с сайта TARA'); // Setup SMTP transport using LOGIN authentication $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'vikabibika0987654321'), 'port' => 587)); $p = ''; foreach ($data as $val) { $p .= '<p>' . $val . '</p>'; } $html = new MimePart($p); $html->type = "text/html"; $body = new MimeMessage(); $body->addPart($html); $message->setBody($body); $transport->setOptions($options); $transport->send($message); }
public function indexAction() { $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $content = $_POST['message']; if ($name == '') { $respond['error'][] = '<b><i class="fa fa-exclamation-triangle"></i> Error : </b>Please fill the name field.'; } if ($email == '') { $respond['error'][] = '<b><i class="fa fa-exclamation-triangle"></i> Error : </b>Please fill the email field.'; } if ($content == '') { $respond['error'][] = '<b><i class="fa fa-exclamation-triangle"></i> Error : </b>Please enter a message.'; } if (@(!$respond['error'])) { $me = '*****@*****.**'; $message = new Message(); $message->addTo('*****@*****.**')->addFrom($email)->setSubject('New message from Claire\'s classes'); // Setup SMTP transport using LOGIN authentication $transport = new SmtpTransport(); $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => $me, 'password' => 'cuzqvajhltsnagof'), 'port' => 587)); $html = new MimePart(' New Message from :<br /><br /> Name : ' . $name . '<br /> Phone : ' . $phone . '<br /> Email : ' . $email . '<br /> Content : ' . $content); $html->type = "text/html"; $body = new MimeMessage(); $body->addPart($html); $message->setBody($body); $transport->setOptions($options); $val = $transport->send($message); $respond['success'] = '<i class="fa fa-check"></i> Your message has been sent!'; } $view = new ViewModel(array('respond' => json_encode($respond))); $view->setTerminal(true); $view->setTemplate('application/ajax/index.phtml'); return $view; }