作者:bitrecruite
项目:CrossApplicantManage
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);
}
作者:control-cor
项目:brand
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;
}
作者:snowio
项目:eternaldeztin
/**
* Sends a mail with the given data from the AppMailAccount
* @param string $to
* @param string $subject
* @param string $content
*/
public function sendMail(string $to, string $subject, string $content, array $files = [])
{
$content .= "\n\nThis is an automated mail. Please don't respond.";
$text = new Mime\Part($content);
$text->type = 'text/plain';
$text->charset = 'utf-8';
$text->disposition = Mime\Mime::DISPOSITION_INLINE;
$parts[] = $text;
foreach ($files as $filePath) {
$fileContent = file_get_contents($filePath);
$attachment = new Mime\Part($fileContent);
$attachment->type = 'image/' . pathinfo($filePath, PATHINFO_EXTENSION);
$attachment->filename = basename($filePath);
$attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Mime\Mime::ENCODING_BASE64;
$parts[] = $attachment;
}
$mime = new Mime\Message();
$mime->setParts($parts);
$appMailData = $this->getAppMailData();
$message = new Message();
$message->addTo($to)->addFrom($appMailData->getAdress())->setSubject($subject)->setBody($mime)->setEncoding('utf-8');
$transport = new SmtpTransport();
$options = new SmtpOptions(['name' => $appMailData->getHost(), 'host' => $appMailData->getHost(), 'connection_class' => 'login', 'connection_config' => ['username' => $appMailData->getLogin(), 'password' => $appMailData->getPassword()]]);
$transport->setOptions($options);
$transport->send($message);
}
作者:reli
项目:rcm-logi
/**
* 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
}
}
作者:gsokolowsk
项目:learnzf
/**
* 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@zend.com', 'Slavey Karadzhov');
$mail->setSubject($translator->translate('Congratulations: Here is your award certificate'));
$transport = $this->services->get('mail-transport');
$transport->send($mail);
}
作者:SalesAndOrder
项目:zf2-mai
/**
* @param ZendMail\Message $message
* @param string $emailAlias
* @param array $variables
* @return ZendMail\Message
* @throws Exception\RuntimeException
*/
public function sendMail(ZendMail\Message $message, $emailAlias, array $variables = array())
{
$plain = $this->renderMessage($emailAlias, Config::TYPE_PLAIN, $variables);
$html = $this->renderMessage($emailAlias, Config::TYPE_HTML, $variables);
$body = new Mime\Message();
if (!empty($html) && !empty($plain)) {
$htmlPart = new Mime\Part($html);
$htmlPart->type = 'text/html';
$plainPart = new Mime\Part($plain);
$plainPart->type = 'text/plain';
$body->setParts(array($plainPart, $htmlPart));
} elseif (!empty($html)) {
$htmlPart = new Mime\Part($html);
$htmlPart->type = 'text/html';
$body->setParts(array($htmlPart));
} else {
$plainPart = new Mime\Part($plain);
$plainPart->type = 'text/plain';
$body->setParts(array($plainPart));
}
$from = $this->getConfig()->getFrom($emailAlias);
$message->setSubject($this->getSubject($emailAlias, $variables))->setEncoding('UTF-8')->setBody($body)->setFrom($from['email'], $from['name']);
if (count($body->getParts()) == 2) {
$message->getHeaders()->get('content-type')->setType('multipart/alternative');
}
if (null === ($transport = $this->getTransport())) {
throw new Exception\RuntimeException('No transport could be alocated');
}
$transport->send($message);
return $message;
}
作者:t4we
项目:mai
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('reciever@mail.com');
$message->getTo()->willReturn($to);
$from = new AddressList();
$from->addFromString('sender@mail.com');
$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());
}
作者:utrenkne
项目:YAWI
/**
* 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);
}
作者:krozne
项目:EventLocationZF
/**
* 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);
}
作者:bhcosta9
项目:zen
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' => 'dispatch@pessoaweb.com.br', '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);
}
}
作者:TimaSipok
项目:MMT300_2015_group
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;
}
作者:Rodrigojorg
项目:frot
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()}!");
}
}
作者:modelframewor
项目:mailservic
/**
* 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;
}
作者:papertas
项目:papertas
/**
* 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);
}
作者:Mendi
项目:ep3-b
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);
}
作者:Kings
项目:ZF_Blo
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@kingsy.co.uk', 'Contact Form - Kingsy.co.uk')->addTo("chris@kingsy.co.uk")->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));
}
作者:rmukra
项目:ekda.or
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);
}
作者:sydorenkov
项目:e-com.lo
private function _setHtmlBody($message = null)
{
$objMimePart = new MimePart($message);
$objMimePart->type = "text/html";
$objMimeMessage = new MimeMessage();
$objMimeMessage->addPart($objMimePart);
return $objMimeMessage;
}
作者:vagovszk
项目:nightlif
private function prepareMimeMessage()
{
$text = new MimePart("This is automaticaly generated message.");
$text->type = "text/plain";
$xml = $this->prepareAttachment();
$body = new MimeMessage();
$body->setParts(array($text, $xml));
return $body;
}
作者:quangdungnin
项目:zendvntea
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());
}