本文整理汇总了PHP中Swift_Image::fromPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Image::fromPath方法的具体用法?PHP Swift_Image::fromPath怎么用?PHP Swift_Image::fromPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Image
的用法示例。
在下文中一共展示了Swift_Image::fromPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: embed
protected function embed($path)
{
if (!$path instanceof Swift_Image) {
$path = Swift_Image::fromPath($path);
}
return $this->message->embed($path);
}
示例2: sendMessage
/**
* @param string $templateName
* @param array $context
* @param string $fromEmail
* @param string $toEmail
*/
protected function sendMessage($templateName, $context, $fromEmail, $toEmail)
{
//new instance
$message = \Swift_Message::newInstance();
$context = $this->twig->mergeGlobals($context);
//merge context
$template = $this->twig->loadTemplate($templateName);
//espacio para agregar imágenes
$context['image_src'] = $message->embed(\Swift_Image::fromPath('images/email_header.png'));
//attach image 1
$context['fb_image'] = $message->embed(\Swift_Image::fromPath('images/fb.gif'));
//attach image 2
$context['tw_image'] = $message->embed(\Swift_Image::fromPath('images/tw.gif'));
//attach image 3
$context['right_image'] = $message->embed(\Swift_Image::fromPath('images/right.gif'));
//attach image 4
$context['left_image'] = $message->embed(\Swift_Image::fromPath('images/left.gif'));
//attach image 5
$subject = $template->renderBlock('subject', $context);
$textBody = $template->renderBlock('body_text', $context);
$htmlBody = $template->renderBlock('body_html', $context);
$message->setSubject($subject)->setFrom($fromEmail)->setTo($toEmail);
if (!empty($htmlBody)) {
$message->setBody($htmlBody, 'text/html')->addPart($textBody, 'text/plain');
} else {
$message->setBody($textBody);
}
$this->mailer->send($message);
}
示例3: insertImages
/**
* Inserts images without using getTemplate.
*
* @param string $message
* @param string $content
*
* @return mixed
*/
public function insertImages($message, $content)
{
foreach ($this->images as $name => $image_path) {
$image_embed = $message->embed(\Swift_Image::fromPath($image_path));
$content = str_replace(rawurlencode('{{ ' . $name . ' }}'), $image_embed, $content);
}
return $content;
}
示例4: postAction
/**
*
* @return RedirectResponse|Response
*/
public function postAction()
{
$urlFrom = $this->getReferer();
if (null == $urlFrom || trim($urlFrom) == '') {
$urlFrom = $this->generateUrl('_front_devis');
}
$devisNewForm = $this->createForm(DevisNewTForm::class);
$request = $this->getRequest();
$reqData = $request->request->all();
if (isset($reqData['DevisNewForm'])) {
$devisNewForm->handleRequest($request);
if ($devisNewForm->isValid()) {
$from = $this->getParameter('mail_from');
$fromName = $this->getParameter('mail_from_name');
$subject = $this->translate('_mail.devis.subject', array(), 'messages');
$mvars = array();
$mvars['firstname'] = $devisNewForm['firstname']->getData();
$mvars['lastname'] = $devisNewForm['lastname']->getData();
$mvars['email'] = $devisNewForm['email']->getData();
$mvars['phone'] = $devisNewForm['phone']->getData();
$mvars['entreprise'] = $devisNewForm['entreprise']->getData();
$mvars['entrepriseForm'] = $devisNewForm['entrepriseForm']->getData();
$mvars['activity'] = $devisNewForm['activity']->getData();
$mvars['dtActivation'] = $devisNewForm['dtActivation']->getData();
$mvars['address'] = $devisNewForm['address']->getData();
$mvars['zipCode'] = $devisNewForm['zipCode']->getData();
$mvars['town'] = $devisNewForm['town']->getData();
$mvars['caYear'] = $devisNewForm['caYear']->getData();
$mvars['nbrInvoicesBuy'] = $devisNewForm['nbrInvoicesBuy']->getData();
$mvars['nbrInvoicesSale'] = $devisNewForm['nbrInvoicesSale']->getData();
$mvars['nbrSalaries'] = $devisNewForm['nbrSalaries']->getData();
$mvars['hasexpert'] = $devisNewForm['hasexpert']->getData();
$mvars['otherInfos'] = $devisNewForm['otherInfos']->getData();
try {
$admins = $this->getParameter('mailtos');
$message = \Swift_Message::newInstance()->setFrom($from, $fromName);
foreach ($admins as $admin) {
$message->addTo($admin['email'], $admin['name']);
$message->setReplyTo($mvars['email'], $mvars['lastname'] . ' ' . $mvars['firstname']);
}
$message->setSubject($subject);
$mvars['logo'] = $message->embed(\Swift_Image::fromPath($this->getParameter('kernel.root_dir') . '/../web/bundles/acfres/images/logo_acf.jpg'));
$message->setBody($this->renderView('AcfFrontBundle:Mail:devis.html.twig', $mvars), 'text/html');
$this->sendmail($message);
} catch (\Exception $e) {
$logger = $this->getLogger();
$logger->addError($e->getMessage());
}
$this->flashMsgSession('success', $this->translate('_front.devis.success'));
return $this->redirect($this->generateUrl('_front_devis'));
} else {
$this->gvars['DevisNewForm'] = $devisNewForm->createView();
$this->flashMsgSession('error', $this->translate('_front.devis.error'));
return $this->renderResponse('AcfFrontBundle:Default:devis.html.twig', $this->gvars);
}
}
return $this->redirect($urlFrom);
}
示例5: _embedContentImages
/**
* @param \Swift_Message $messageInstance
* @param $contentHtml
* @param array $embeddedImages
*
* @return mixed
*/
protected function _embedContentImages(\Swift_Message $messageInstance, $contentHtml, array $embeddedImages)
{
if ($embeddedImages !== NULL) {
foreach ($embeddedImages as $stackIndex => $pathImage) {
$cid = $messageInstance->embed(\Swift_Image::fromPath($pathImage));
$contentHtml = str_replace('{{imageStackIndex:' . $stackIndex . '}}', $cid, $contentHtml);
}
}
return $contentHtml;
}
示例6: embedImage
/**
* Embed the image in message and replace the image link by attachment id.
*
* @param \Swift_Message $message The swift mailer message
* @param \DOMAttr $node The dom attribute of image
* @param array $images The map of image ids passed by reference
*/
protected function embedImage(\Swift_Message $message, \DOMAttr $node, array &$images)
{
if (0 === strpos($node->nodeValue, 'cid:')) {
return;
}
if (isset($images[$node->nodeValue])) {
$node->nodeValue = $images[$node->nodeValue];
} else {
$node->nodeValue = EmbedImageUtil::getLocalPath($node->nodeValue, $this->webDir, $this->hostPattern);
$cid = $message->embed(\Swift_Image::fromPath($node->nodeValue));
$images[$node->nodeValue] = $cid;
$node->nodeValue = $cid;
}
}
示例7: sendMail
public static function sendMail($name, $email, $template)
{
$message = Swift_Message::newInstance()->setSubject($template->getSubject())->setFrom(array('dahlen@dahlenstudio.com' => 'Dahlen'))->setTo(array($email => $name));
$imageMatches = array();
$html = $template->getHTML();
if (preg_match_all('/<img.*?src="(.*?)".*?\\/>/', $html, $imageMatches, PREG_PATTERN_ORDER) > 0) {
foreach ($imageMatches[0] as $index => $fullMatch) {
$html = str_replace($imageMatches[1][$index], $message->embed(Swift_Image::fromPath(str_replace('http://' . $_SERVER['SERVER_NAME'], ROOT_DIR, $imageMatches[1][$index]), $html)), $html);
}
}
$message->setBody($html, 'text/html')->addPart($template->getPlainText(), 'text/plain');
$transport = Swift_SmtpTransport::newInstance(self::$SMTP_SERVER, 25)->setUsername(self::$USERNAME)->setPassword(self::$PASSWORD);
$mailer = Swift_Mailer::newInstance($transport);
return $mailer->send($message);
}
示例8: envoyerMailTousLesAbonnes
public function envoyerMailTousLesAbonnes(Notification $notif)
{
//On récupère tous les abonnés en base de donnée
$abonnes = $this->repo->findAll();
//On construit le mail à envoyer (objet, corps du message, inclusion d'images)
$objet = str_replace("{SUJET}", $notif->getSujet(), $this->mailSubject);
$message = \Swift_Message::newInstance($objet);
$urlLogoSopra = "http://localhost" . $this->container->get('templating.helper.assets')->getUrl('images/logo.png');
$urlLogoSopra = $message->embed(\Swift_Image::fromPath($urlLogoSopra));
$message->setFrom($this->mailSender)->setBody($this->templating->render('AbonnementBundle:Abonne:mail.html.twig', array("lien" => $notif->getLien(), "resume" => $notif->getResume(), "urlImage" => $urlLogoSopra)), 'text/html');
//On envoie un mail à chaque abonné :
foreach ($abonnes as $abonne) {
$message->setTo($abonne->getMail());
$this->mailer->send($message);
}
}
示例9: rechazarAction
public function rechazarAction($id)
{
//Enviar correo al estudiante
$em = $this->getDoctrine()->getManager();
$solicitud = $em->getRepository('EstudianteBundle:Solicitud')->find($id);
$estudiante = $solicitud->getEstudiante();
/* * ********************Mail ****************************** */
$message = \Swift_Message::newInstance('Solicitud Rechazada');
$message->setFrom('evalua.ucab@gmail.com');
$message->setTo($estudiante->getCorreo());
$message->setBody('<html>' . ' <head> <img src="' . $message->embed(\Swift_Image::fromPath('images/logoHeader.png')) . '" /></head>' . ' <body>' . ' <br><br><br><span style="font-size:18px">Estimado estudiante, su solicitud a la sección ' . $solicitud->getSeccion()->getMateria()->getNombre() . '-' . $solicitud->getSeccion()->getCodigo() . ' ha sido rechazada por el profesor. </span> ' . ' </body>' . '<br><br><br><footer>EvaluaUcab Todos los derechos reservados</footer>' . '</html>', 'text/html');
$this->get('mailer')->send($message);
$solicitud->setStatus('Rechazada');
/* * ****************************************************** */
$em->remove($solicitud);
$em->flush();
$this->getRequest()->getSession()->getFlashBag()->add('warning', '¡Solicitud Rechazada!');
return $this->render('ProfesorBundle:Default:solicitudes.html.twig');
}
示例10: sendTemplateMail
public function sendTemplateMail(SendTemplateMailCommand $command)
{
$message = \Swift_Message::newInstance();
$ext = $command->format === 'text/html' ? 'html' : 'txt';
$tplIdentifier = 'Email/' . $command->template . '.' . $ext;
$template = $this->cr->getContent($tplIdentifier);
$templateData = $command->templateData;
if ($command->image !== null) {
$templateData['image'] = $message->embed(\Swift_Image::fromPath($command->image));
}
// Subject
$env = new \Twig_Environment(new \Twig_Loader_String());
$subject = $template->getProperties()->containsKey('subject') ? $template->getProperties()->get('subject') : $this->mailFromName;
$subject = $env->render($subject, $templateData);
// Body
$body = $this->templating->render('bcrm_content:' . $tplIdentifier, $templateData);
$message->setCharset('UTF-8');
$message->setFrom($this->mailFromEmail, $this->mailFromName)->setSubject($subject)->setTo($command->email)->setBody($body, $command->format);
$this->mailer->send($message);
}
示例11: embedImages
/**
* @param Swift_Mime_Message $message
* @param Swift_Mime_MimeEntity $part
*
* @return string
*/
protected function embedImages(Swift_Mime_Message $message, Swift_Mime_MimeEntity $part = null)
{
$body = $part === null ? $message->getBody() : $part->getBody();
$dom = new \DOMDocument('1.0');
$dom->loadHTML($body);
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
/**
* Prevent beforeSendPerformed called twice
* see https://github.com/swiftmailer/swiftmailer/issues/139
*/
if (strpos($src, 'cid:') === false) {
$entity = \Swift_Image::fromPath($src);
$message->setChildren(array_merge($message->getChildren(), [$entity]));
$image->setAttribute('src', 'cid:' . $entity->getId());
}
}
return $dom->saveHTML();
}
示例12: transform
/**
* {@inheritdoc)
*/
public function transform(\Swift_Mime_Message $message)
{
$body = $message->getBody();
$body = preg_replace_callback('/(src|background)="(http[^"]*)"/', function ($matches) use($message) {
$attribute = $matches[1];
$imagePath = $matches[2];
if ($fp = fopen($imagePath, "r")) {
$imagePath = $message->embed(\Swift_Image::fromPath($imagePath));
fclose($fp);
}
return sprintf('%s="%s"', $attribute, $imagePath);
}, $body);
$body = preg_replace_callback('/url\\((http[^"]*)\\)/', function ($matches) use($message) {
$imagePath = $matches[1];
if ($fp = fopen($imagePath, "r")) {
$imagePath = $message->embed(\Swift_Image::fromPath($imagePath));
fclose($fp);
}
return sprintf('url(%s)', $imagePath);
}, $body);
$message->setBody($body, 'text/html');
}
示例13: testEmbeddedImagesAreEmbedded
public function testEmbeddedImagesAreEmbedded()
{
$message = Swift_Message::newInstance()->setFrom('from@example.com')->setTo('to@example.com')->setSubject('test');
$cid = $message->embed(Swift_Image::fromPath(__DIR__ . '/../../_samples/files/swiftmailer.png'));
$message->setBody('<img src="' . $cid . '" />', 'text/html');
$that = $this;
$messageValidation = function (Swift_Mime_Message $message) use($that) {
preg_match('/cid:(.*)"/', $message->toString(), $matches);
$cid = $matches[1];
preg_match('/Content-ID: <(.*)>/', $message->toString(), $matches);
$contentId = $matches[1];
$that->assertEquals($cid, $contentId, 'cid in body and mime part Content-ID differ');
return true;
};
$failedRecipients = array();
$transport = m::mock('Swift_Transport');
$transport->shouldReceive('isStarted')->andReturn(true);
$transport->shouldReceive('send')->with(m::on($messageValidation), $failedRecipients)->andReturn(1);
$memorySpool = new Swift_MemorySpool();
$memorySpool->queueMessage($message);
$memorySpool->flushQueue($transport, $failedRecipients);
}
示例14: editPostAction
/**
*
* @param string $uid
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function editPostAction($uid)
{
$urlFrom = $this->getReferer();
if (null == $urlFrom || trim($urlFrom) == '') {
$urlFrom = $this->generateUrl('_admin_company_list');
}
$em = $this->getEntityManager();
try {
$customer = $em->getRepository('AcfDataBundle:Customer')->find($uid);
if (null == $customer) {
$this->flashMsgSession('warning', $this->translate('Customer.edit.notfound'));
} else {
$traces = $em->getRepository('AcfDataBundle:Trace')->getAllByEntityId($customer->getId(), Trace::AE_CUSTOMER);
$this->gvars['traces'] = array_reverse($traces);
$customerUpdateForm = $this->createForm(CustomerUpdateTForm::class, $customer);
$customerUpdateDocsForm = $this->createForm(CustomerUpdateDocsTForm::class, $customer, array('company' => $customer->getCompany()));
$doc = new Doc();
$doc->setCompany($customer->getCompany());
$docNewForm = $this->createForm(DocNewTForm::class, $doc, array('company' => $customer->getCompany()));
$this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2);
$this->getSession()->remove('tabActive');
$this->gvars['stabActive'] = $this->getSession()->get('stabActive', 1);
$this->getSession()->remove('stabActive');
$request = $this->getRequest();
$reqData = $request->request->all();
$cloneCustomer = clone $customer;
if (isset($reqData['CustomerUpdateForm'])) {
$this->gvars['tabActive'] = 2;
$this->getSession()->set('tabActive', 2);
$customerUpdateForm->handleRequest($request);
if ($customerUpdateForm->isValid()) {
$em->persist($customer);
$em->flush();
$this->flashMsgSession('success', $this->translate('Customer.edit.success', array('%customer%' => $customer->getLabel())));
$this->traceEntity($cloneCustomer, $customer);
return $this->redirect($urlFrom);
} else {
$em->refresh($customer);
$this->flashMsgSession('error', $this->translate('Customer.edit.failure', array('%customer%' => $customer->getLabel())));
}
} elseif (isset($reqData['DocNewForm'])) {
$this->gvars['tabActive'] = 3;
$this->getSession()->set('tabActive', 3);
$this->gvars['stabActive'] = 1;
$this->getSession()->set('stabActive', 1);
$docNewForm->handleRequest($request);
if ($docNewForm->isValid()) {
$docs = array();
$docFiles = $docNewForm['fileName']->getData();
$docDir = $this->getParameter('kernel.root_dir') . '/../web/res/docs';
$docNames = '';
foreach ($docFiles as $docFile) {
$originalName = $docFile->getClientOriginalName();
$fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($docFile->getClientOriginalExtension());
$mimeType = $docFile->getMimeType();
$docFile->move($docDir, $fileName);
$size = filesize($docDir . '/' . $fileName);
$md5 = md5_file($docDir . '/' . $fileName);
$doc = new Doc();
$doc->setCompany($customer->getCompany());
$doc->setFileName($fileName);
$doc->setOriginalName($originalName);
$doc->setSize($size);
$doc->setMimeType($mimeType);
$doc->setMd5($md5);
$doc->setDescription($docNewForm['description']->getData());
$em->persist($doc);
$customer->addDoc($doc);
$docNames .= $doc->getOriginalName() . ' ';
$docs[] = $doc;
}
$em->persist($customer);
$em->flush();
$this->flashMsgSession('success', $this->translate('Doc.add.success', array('%doc%' => $docNames)));
$from = $this->getParameter('mail_from');
$fromName = $this->getParameter('mail_from_name');
$subject = $this->translate('_mail.newdocsCloud.subject', array(), 'messages');
$company = $customer->getCompany();
$acfCloudRole = $em->getRepository('AcfDataBundle:Role')->findOneBy(array('name' => 'ROLE_CLIENT1'));
$users = array();
foreach ($company->getUsers() as $user) {
if ($user->hasRole($acfCloudRole)) {
$users[] = $user;
}
}
if (\count($users) != 0) {
foreach ($users as $user) {
$mvars = array();
$mvars['company'] = $company;
$mvars['docs'] = $docs;
$message = \Swift_Message::newInstance();
$message->setFrom($from, $fromName);
$message->addTo($user->getEmail(), $user->getFullname());
$message->setSubject($subject);
$mvars['logo'] = $message->embed(\Swift_Image::fromPath($this->getParameter('kernel.root_dir') . '/../web/bundles/acfres/images/logo_acf.jpg'));
//.........这里部分代码省略.........
示例15: embedImages
/**
* embed images to the given body
*
* @param string $body
* @return string
*/
protected function embedImages($body)
{
foreach ($this->embedded as $image) {
if (false !== strpos($body, $this->embeddedUrl . $image)) {
$cid = $this->message->embed(Swift_Image::fromPath($this->embeddedDir . $image));
$body = str_replace($this->embeddedUrl . $image, $cid, $body);
}
}
return $body;
}