本文整理汇总了PHP中Zend\Mime\Message::setParts方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::setParts方法的具体用法?PHP Message::setParts怎么用?PHP Message::setParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mime\Message
的用法示例。
在下文中一共展示了Message::setParts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
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);
}
示例2: 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;
}
示例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: 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()}!");
}
}
示例6: 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);
}
示例7: 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);
}
}
示例8: 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;
}
示例9: sendHTML
public function sendHTML($to, $from, $subject, $html, $attachments = false, $headers = false, $plain = false, $inlineImages = false)
{
if ($inlineImages) {
user_error('The SES mailer does not support inlining images', E_USER_NOTICE);
}
$htmlPart = new Mime\Part($html);
$htmlPart->type = Mime\Mime::TYPE_HTML;
$htmlPart->charset = 'utf-8';
$htmlPart->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
$plainPart = new Mime\Part($plain ?: \Convert::xml2raw($html));
$plainPart->type = Mime\Mime::TYPE_TEXT;
$plainPart->charset = 'utf-8';
$plainPart->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
$alternatives = new Mime\Message();
$alternatives->setParts(array($plainPart, $htmlPart));
$alternativesPart = new Mime\Part($alternatives->generateMessage());
$alternativesPart->type = Mime\Mime::MULTIPART_ALTERNATIVE;
$alternativesPart->boundary = $alternatives->getMime()->boundary();
$body = new Mime\Message();
$body->addPart($alternativesPart);
if ($attachments) {
$this->addAttachments($body, $attachments);
}
$this->sendMessage($to, $from, $subject, $body, $headers);
}
示例10: 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);
}
示例11: submitAction
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));
}
示例12: 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);
}
示例13: 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);
}
示例14: prepareMimeMessage
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;
}
示例15: sendEmail
/**
* sendEmail
* @param mixed $tags -Array of the Macros need to be replaced defined in Email template
* @param string $emailKey -unique email key to fetch the email template
* @param integer $userId -UserId of the user to which the email to be sent.
* default is 0 for admin
* @return integer 1-success 2-error
* @author Manu Garg
*/
public function sendEmail($tags, $emailKey, $userId = 0, $filename = "")
{
$em = $this->getEntityManager();
$adminemailObj = $em->getRepository('Admin\\Entity\\Settings')->findOneBy(array('metaKey' => 'admin_email'));
$supportemailObj = $em->getRepository('Admin\\Entity\\Settings')->findOneBy(array('metaKey' => 'admin_support_email'));
$adminemail = $adminemailObj->getMetaValue();
$supportemail = $supportemailObj->getMetaValue();
/* Fetching Email Template */
$emailObj = $em->getRepository('Admin\\Entity\\Email')->findOneBy(array('keydata' => $emailKey, 'isActive' => 1));
if (!empty($userId)) {
/* Fetching User */
$userObj = $em->getRepository('Admin\\Entity\\Users')->find($userId);
}
if (!empty($emailObj)) {
$emailSubject = $emailObj->getSubject();
$mailContent = $emailObj->getContent();
foreach ($tags as $key => $value) {
//replace the Macros defined in email body with values
$mailContent = str_replace($key, $value, $mailContent);
}
$mail = new Mail\Message();
$html = new MimePart($mailContent);
$html->type = "text/html";
$body = new MimeMessage();
$body->setParts(array($html));
$attachment = array();
if ($filename != "") {
$fileContent = fopen($filename, 'r');
$attachment = new Mime\Part($fileContent);
$attachment->type = 'image/jpg';
$attachment->filename = 'image-file-name.jpg';
$attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
// Setting the encoding is recommended for binary data
$attachment->encoding = Mime::ENCODING_BASE64;
$body->setParts(array($html, $attachment));
}
/* Set Email Body */
$mail->setBody($body);
/* Set Email From Address */
$mail->setFrom($adminemail, 'Support');
if (!empty($userId)) {
$mail->addTo($userObj->getEmail(), $userObj->getFirstName() . " " . $userObj->getLastName());
} else {
/* Need to replace with admin email if need to send email to admin */
$mail->addTo($supportemail, "tapetickets");
}
$mail->setSubject($emailSubject);
/* Set Email Subject */
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
return 1;
} else {
return 2;
}
}