本文整理汇总了PHP中Zend\Mime\Message类的典型用法代码示例。如果您正苦于以下问题:PHP Message类的具体用法?PHP Message怎么用?PHP Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateBody
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);
}
示例2: send
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;
}
示例3: sendMail
/**
* 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);
}
示例4: sendRestPasswordEmail
/**
* 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
}
}
示例5: sendCertificate
/**
* 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);
}
示例6: sendMail
/**
* @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;
}
示例7: testInvoke
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());
}
示例8: generateBody
/**
* 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);
}
示例9: sendNotificationMail
/**
* 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);
}
示例10: send
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);
}
}
示例11: sendCareerMail
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;
}
示例12: sendEmail
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()}!");
}
}
示例13: packData
/**
* 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;
}
示例14: sendContactMail
/**
* 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);
}
示例15: send
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);
}