protected function _swiftMail($to, $from, $subject, $message, $attachments = [], $html = true) { $mailer = $this->__getSwiftMailer($from); if (is_array($to) && isset($to['email'])) { if (isset($to['name'])) { $to = [$to['email'] => $to['name']]; } else { $to = $to['email']; } } $mail = new \Swift_Message(); $mail->setSubject($subject)->setFrom($from['email'], $from['name'])->setTo($to); if (isset($from['reply-to'])) { if (is_array($from['reply-to']) && isset($from['email'])) { $mail->setReplyTo($from['reply-to']['email'], $from['reply-to']['name']); } else { $mail->setReplyTo($from['reply-to']); } } $mail->setBody($message, $html ? 'text/html' : 'text/plain'); foreach ($attachments as $attachment) { $mail->attach(\Swift_Attachment::fromPath($attachment)); } return $mailer->send($mail); }
/** * * @param array $o * @throws InvalidArgumentException * @return multitype:NULL string |multitype:NULL |number * */ public function sendBasic(smMailMessage $smMailMessage, array $options) { $this->smMailMessage = $smMailMessage; $message = Swift_Message::newInstance(); $this->setSMTPData($message, $options['account']); $this->feedAddress($message, 'to', $this->smMailMessage->to); $this->feedAddress($message, 'cc', $this->smMailMessage->cc); $this->feedAddress($message, 'bcc', $this->smMailMessage->bcc); $message->setFrom(array($smMailMessage->from => $smMailMessage->fromName ? $smMailMessage->fromName : $this->from)); $message->setSender($smMailMessage->sender); $message->addReplyTo($this->smMailMessage->replyTo); $message->setSubject($smMailMessage->subject); $headers = $message->getHeaders(); if (count($this->customheaders) > 0) { foreach ($this->customheaders as $kc => $vc) { $headers->addTextHeader(array($kc, $vc)); } } foreach ($smMailMessage->attachments as $k => $v) { $message->attach(Swift_Attachment::fromPath($v)); } $type = $message->getHeaders()->get('Content-Type'); $type->setValue('text/html'); $type->setParameter('charset', $this->charset); $message->setBody($smMailMessage->HTMLBody)->addPart($smMailMessage->HtmlToTextBody()); $success = $this->mailer->send($message, $error) > 0; return array('success' => $success, 'mailStream' => $success ? $message->toString() : null, 'error' => $error); }
protected function attach($attachment) { if (!$attachment instanceof Swift_Attachment) { $attachment = Swift_Attachment::fromPath($attachment); } return $this->message->attach($attachment); }
protected function execute(InputInterface $input, OutputInterface $output) { //generacion xlsx $em = $this->getContainer()->get('doctrine')->getManager(); $emailDara = $em->getRepository('BackendBundle:EmailList')->findOneByName('Email Dara'); $researches = $em->getRepository('BackendBundle:Research')->programationUnsendedToDara(); $date = date("d-M-Y h:i:s"); if (count($researches) == 0) { $output->writeln($date . ": No hay programaciones para este periodo"); } else { try { $this->generateProgramacionXLSX($researches); } catch (Exception $e) { $output->writeln($e->getMessage()); return $e->getMessage(); } $output->writeln($date . ": Programacion generada"); //enviar por email $today = date("d-M-Y"); $filename = "Programacion_" . $today; $path = $this->getContainer()->get('kernel')->getRootDir() . "/../web/Programaciones/"; $message = \Swift_Message::newInstance()->setSubject('Programación de Cursos IPre')->setFrom('*****@*****.**')->setTo(array($emailDara->getEmail()))->setBody("Hola, adjuntamos la programación de cursos de este mes, saludos, \nGestión IPre")->attach(\Swift_Attachment::fromPath($path . $filename . ".xlsx")); $this->getContainer()->get('mailer')->send($message); $output->writeln($date . ": Programacion enviada"); // seteamos los estados como programacion envada a dara foreach ($researches as $research) { $research->getApplication()->setState(4); $em->flush(); } } }
/** * Send a email using t3lib_htmlmail or the new swift mailer * It depends on the TYPO3 version */ public static function sendEmail($to, $subject, $message, $type = 'plain', $fromEmail = '', $fromName = '', $charset = 'utf-8', $files = array()) { $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage'); $mail->setTo(explode(',', $to)); $mail->setSubject($subject); $mail->setCharset($charset); $mail->setFrom(array($fromEmail => $fromName)); $mail->setReplyTo(array($fromEmail => $fromName)); // add Files if (!empty($files)) { foreach ($files as $file) { $mail->attach(Swift_Attachment::fromPath($file)); } } // add Plain if ($type == 'plain') { $mail->addPart($message, 'text/plain'); } // add HTML if ($type == 'html') { $mail->setBody($message, 'text/html'); } // send $mail->send(); }
/** * Send email when processing the form data. * * @param Event $event */ public function onFormProcessed(Event $event) { $form = $event['form']; $action = $event['action']; $params = $event['params']; if (!$this->email->enabled()) { return; } switch ($action) { case 'email': // Prepare Twig variables $vars = array('form' => $form); // Build message $message = $this->buildMessage($params, $vars); if (isset($params['attachments'])) { $filesToAttach = (array) $params['attachments']; if ($filesToAttach) { foreach ($filesToAttach as $fileToAttach) { $filesValues = $form->value($fileToAttach); if ($filesValues) { foreach ($filesValues as $fileValues) { $filename = $fileValues['file']; $message->attach(\Swift_Attachment::fromPath($filename)); } } } } } // Send e-mail $this->email->send($message); break; } }
public function send($lastOverride = false) { $i18n = Localization::getTranslator(); $lastFn = '/home/pi/phplog/last-tx-sent'; $last = 0; if (file_exists($lastFn)) { $last = intval(trim(file_get_contents($lastFn))); } if ($lastOverride !== false) { $last = $lastOverride; } $csvMaker = Container::dispense('TransactionCSV'); $config = Admin::volatileLoad()->getConfig(); $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword()); $msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('See attached for transaction log.')); $file = $csvMaker->save($last); if (!$file) { throw new Exception('Unable to save CSV'); } $msg->attach(Swift_Attachment::fromPath($file)); file_put_contents($lastFn, $csvMaker->getLastID()); $mailer = Swift_Mailer::newInstance($transport); if (!$mailer->send($msg)) { throw new Exception('Unable to send: unkown cause'); } }
public function sendMail() { $transport = Swift_SmtpTransport::newInstance($this->instance, $this->smtp_port); $transport->setUsername($this->username); $transport->setPassword($this->user_password); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance(); $message->setFrom($this->setFrom); $message->setTo($this->setTo); $message->setSubject($this->subject); $message->setBody($this->setBody, 'text/html', 'utf-8'); if (!empty($this->setfilepath)) { $message->attach(Swift_Attachment::fromPath($this->setfilepath)->setFilename($this->aliasname)); } /*try{ if($mailer->send($message)){ return true; } } catch (Swift_ConnectionException $e){ //echo 'There was a problem communicating with SMTP: ' . $e->getMessage(); return false; }*/ return $mailer->send($message); }
static function send($title, $body, $to_array, $attachment = null, $log = true) { $model = Config::find()->one(); // Create the message $message = \Swift_Message::newInstance()->setSubject($title)->setFrom(array($model->from_email => $model->from_name))->setTo($to_array)->setBody($body); // Optionally add any attachments if ($attachment) { if (is_array($attachment)) { foreach ($attachment as $file) { $message = $message->attach(Swift_Attachment::fromPath($file)); } } else { $message = $message->attach(Swift_Attachment::fromPath($attachment)); } } // Create the Transport switch ($model->type) { case 1: $transport = \Swift_SmtpTransport::newInstance($model->smtp, $model->port > 0 ?: 25)->setUsername($model->from_email)->setPassword($model->pass); break; case 2: $transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); break; case 3: $transport = \Swift_MailTransport::newInstance(); break; } $mailer = \Swift_Mailer::newInstance($transport); $result = $mailer->send($message); //log send mail if (true === $log) { static::log($to_array, $title, $body, $attachment); } }
public static function sendEmail($receiver, $obj = "Aucun objet", $content = "", $urlFile = "", $nameFile = "") { global $config; global $twig; $message = Swift_Message::newInstance(); $template = $twig->loadTemplate("email_generique.html5.twig"); $view = $template->render(["objEmail" => $obj, "messageEmail" => $content]); $arrMatches = array(); preg_match_all('/(src=|url\\()"([^"]+\\.(jpe?g|png|gif|bmp|tiff?|swf))"/Ui', $view, $arrMatches); foreach (array_unique($arrMatches[2]) as $url) { $src = rawurldecode($url); // see #3713 if (!preg_match('@^https?://@', $src) && file_exists(BASE_ROOT . '/' . $src)) { $cid = $message->embed(Swift_EmbeddedFile::fromPath(BASE_ROOT . '/' . $src)); $view = str_replace(array('src="' . $url . '"', 'url("' . $url . '"'), array('src="' . $cid . '"', 'url("' . $cid . '"'), $view); } } $message->setSubject($obj); $message->setFrom($config["smtp"]["sender"]); $message->setReplyTo($config["smtp"]["replyTo"]); $message->setTo($receiver); $message->setBody($view, 'text/html'); if ($urlFile !== "") { $message->attach(Swift_Attachment::fromPath($urlFile)->setFilename($nameFile)); } $mailer = self::getMailer(); $mailer->send($message); }
/** * Sends out an email to specified recipients using given message and other optional parameters. * @param array $components Mixed value array containing components to create a message. * @return integer number of recipients the message was sent to. */ function mailSender($components) { //Create transport $transport = Swift_SmtpTransport::newInstance('insert mail/smtp server here', 25)->setUsername('insert username here')->setPassword('insert password here'); //Create mail using transport $mailer = Swift_Mailer::newInstance($transport); //Create message. Minimum required: from, to, subject, message. $message = Swift_Message::newInstance(); $message->setSubject($components['subject'])->setFrom($components['from'])->setTo($components['to'])->setBody($components['body'], 'text/html'); //Optional parameters. Check to see if array contains additional parameters to add to the message. if (array_key_exists('bcc', $components)) { $message->setBcc($components['bcc']); } if (array_key_exists('cc', $components)) { $message->setCc($components['cc']); } if (array_key_exists('attachment', $components)) { if (is_array($components['attachment'])) { foreach ($components['attachment'] as $attachment) { $message->attach(Swift_Attachment::fromPath($attachment)); } } else { $message->attach(Swift_Attachment::fromPath($components['attachment'])); } } return $mailer->send($message); }
/** * Calendar attachment constructor * * @param Calendar $calendar */ public function __construct(Calendar $calendar) { $data = $calendar->createCalendar(); $filename = $calendar->getConfig('filename'); $contentType = $calendar->getContentType(); parent::__construct($data, $filename, $contentType); }
public function testAttachmentSending() { $mailer = $this->_getMailer(); $message = Swift_Message::newInstance('[Swift Mailer] HtmlWithAttachmentSmokeTest')->setFrom(array(SWIFT_SMOKE_EMAIL_ADDRESS => 'Swift Mailer'))->setTo(SWIFT_SMOKE_EMAIL_ADDRESS)->attach(Swift_Attachment::fromPath($this->_attFile))->setBody('<p>This HTML-formatted message should contain an attached ZIP file (named "textfile.zip").' . PHP_EOL . 'When unzipped, the archive should produce a text file which reads:</p>' . PHP_EOL . '<p><q>This is part of a Swift Mailer v4 smoke test.</q></p>', 'text/html'); $this->assertEqual(1, $mailer->send($message), '%s: The smoke test should send a single message'); $this->_visualCheck('http://swiftmailer.org/smoke/4.0.0/html_with_attachment.jpg'); }
public function testSend() { $message = new Swift_Message(); $message->setFrom('*****@*****.**', 'Johnny #5'); $message->setSubject('Is alive!'); $message->addTo('*****@*****.**', 'A. Friend'); $message->addTo('*****@*****.**'); $message->addCc('*****@*****.**'); $message->addCc('*****@*****.**', 'Extra 2'); $message->addBcc('*****@*****.**'); $message->addBcc('*****@*****.**', 'Extra 4'); $message->addPart('<q>Help me Rhonda</q>', 'text/html'); $message->addPart('Doo-wah-ditty.', 'text/plain'); $attachment = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain'); $attachment2 = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain'); $attachment2->setDisposition('inline'); $message->attach($attachment); $message->attach($attachment2); $message->setPriority(1); $headers = $message->getHeaders(); $headers->addTextHeader('X-PM-Tag', 'movie-quotes'); $messageId = $headers->get('Message-ID')->getId(); $transport = new PostmarkTransportStub('TESTING_SERVER'); $client = $this->getMock('GuzzleHttp\\Client', array('request')); $transport->setHttpClient($client); $o = PHP_OS; $v = phpversion(); $client->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('https://api.postmarkapp.com/email'), $this->equalTo(['headers' => ['X-Postmark-Server-Token' => 'TESTING_SERVER', 'User-Agent' => "swiftmailer-postmark (PHP Version: {$v}, OS: {$o})", 'Content-Type' => 'application/json'], 'json' => ['From' => '"Johnny #5" <*****@*****.**>', 'To' => '"A. Friend" <*****@*****.**>,you+two@example.com', 'Cc' => 'another+1@example.com,"Extra 2" <*****@*****.**>', 'Bcc' => 'another+3@example.com,"Extra 4" <*****@*****.**>', 'Subject' => 'Is alive!', 'Tag' => 'movie-quotes', 'TextBody' => 'Doo-wah-ditty.', 'HtmlBody' => '<q>Help me Rhonda</q>', 'Headers' => [['Name' => 'Message-ID', 'Value' => '<' . $messageId . '>'], ['Name' => 'X-PM-KeepID', 'Value' => 'true'], ['Name' => 'X-Priority', 'Value' => '1 (Highest)']], 'Attachments' => [['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt'], ['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt', 'ContentID' => 'cid:' . $attachment2->getId()]]]])); $transport->send($message); }
protected function sendMessage($templateName, $context, $fromEmail, $toEmail, array $attachments = array()) { $template = $this->twig->loadTemplate($templateName); $subject = $template->renderBlock('subject', $context); $textBody = $template->renderBlock('body_text', $context); $htmlBody = $template->renderBlock('body_html', $context); $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($fromEmail)->setTo($toEmail); if (!empty($htmlBody)) { $message->setBody($htmlBody, 'text/html')->addPart($textBody, 'text/plain'); } else { $message->setBody($textBody); } if (is_array($attachments) && !empty($attachments)) { foreach ($attachments as $filename => $path) { //TODO need to assure to use correct absolute path! if (file_exists($path)) { $attachment = \Swift_Attachment::fromPath($path); if (is_string($filename)) { $attachment->setFilename($filename); } $message->attach($attachment); } } } $this->mailer->send($message); }
public static function to($email, $subject, $content, $part, $attach) { $mailconfig = Config::get('mail'); $transport = \Swift_SmtpTransport::newInstance($mailconfig['host'], $mailconfig['port'])->setUsername($mailconfig['username'])->setPassword($mailconfig['password']); // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Create the message $message = \Swift_Message::newInstance($subject)->setFrom(array($mailconfig['from']['address'] => $mailconfig['from']['name'])); // Set the To addresses with an associative array if (!is_array($email)) { throw new \Exception("发送邮件必须是关联数组", 1); } $message->setTo($email); // Give it a body $message->setBody($content); // And optionally an alternative body if ($part) { $message->addPart($part, 'text/html'); } // Optionally add any attachments if ($attach) { $message->attach(Swift_Attachment::fromPath($attach)); } // Send the message if (!$mailer->send($message, $failures)) { return $failures; } else { return true; } }
public function postUpdate(LifecycleEventArgs $args) { $entity = $args->getEntity(); $this->mailer = $this->container->get('mailer'); $this->mailerHelper = $this->container->get('stfalcon_event.mailer_helper'); $this->pdfGeneratorHelper = $this->container->get('stfalcon_event.pdf_generator.helper'); if ($entity instanceof Payment) { if ($entity->getStatus() === Payment::STATUS_PAID) { $tickets = $this->container->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Ticket')->getAllTicketsByPayment($entity); /** @var Ticket $ticket */ foreach ($tickets as $ticket) { /** @var $user User */ $user = $ticket->getUser(); /** @var Event $event */ $event = $ticket->getEvent(); $successPaymentTemplateContent = $this->mailerHelper->renderTwigTemplate('StfalconEventBundle:Interkassa:_mail.html.twig', ['user' => $user, 'event' => $event]); $mail = new Mail(); $mail->addEvent($event); $mail->setText($successPaymentTemplateContent); $html = $this->pdfGeneratorHelper->generateHTML($ticket); $message = $this->mailerHelper->formatMessage($user, $mail); $message->setSubject($event->getName())->attach(\Swift_Attachment::newInstance($this->pdfGeneratorHelper->generatePdfFile($ticket, $html), $ticket->generatePdfFilename())); $this->mailer->send($message); } } } }
/** * {@inheritdoc} */ public function send($from, $to, $subject, $body, $replyTo = null, $attachments = []) { $message = new \Swift_Message($subject, $body); // set from and to $message->setFrom($from); $message->setTo($to); // set attachments if (count($attachments) > 0) { foreach ($attachments as $file) { if ($file instanceof \SplFileInfo) { $path = $file->getPathName(); $name = $file->getFileName(); // if uploadedfile get original name if ($file instanceof UploadedFile) { $name = $file->getClientOriginalName(); } $message->attach(\Swift_Attachment::fromPath($path)->setFilename($name)); } } } // set replyTo if ($replyTo != null) { $message->setReplyTo($replyTo); } return $this->mailer->send($message); }
/** * Listen contact message request; */ private function handle(Request $request) { $email = $request->request->get('feedback_user_email'); $name = $request->request->get('feedback_user_name'); $email = $request->request->get('feedback_user_email'); $subject = $request->request->get('feedback_subject'); $message = $request->request->get('feedback_message'); $captcha = $request->request->get('g-recaptcha-response'); if (empty($email) || empty($message)) { return; } if (!$this->captchaIsValid($captcha)) { return; } $uploadedFile = $request->files->get('lampiran'); $attachedFile = false; if ($uploadedFile) { // NOTE: $attachedFile variable is used below for mail attachment $attachedFile = $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getClientOriginalName(); $uploadedFileSize = $uploadedFile->getSize(); $uploadedFileSizeLimit = static::fileUploadMaxSize(); if ($uploadedFileSize > $uploadedFileSizeLimit) { // @todo change this to template echo '<script>alert("FILE TOO BIG");</script>'; echo '<script>setTimeout(function(){ window.location = window.location.href }, 2000);</script>'; exit; } $uploadedFile->move($uploadedFile->getPath(), $uploadedFile->getClientOriginalName()); } try { $messageBody = sprintf(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'mail_format.php'), $name, $email, $subject, $message); $smtpUser = $this->getOption('smtp_user'); $smtpPass = $this->getOption('smtp_pass'); $smtpHost = $this->getOption('smtp_host'); $smtpPort = $this->getOption('smtp_port', 465); $smtpSsl = $this->getOption('smtp_ssl', 0); $mailFrom = $smtpUser; $mailFromName = $this->getOption('mail_from_name'); $mailTos = $this->getMailTos(); $message = Swift_Message::newInstance()->setSubject($subject)->setFrom($mailFrom, $mailFromName)->setTo($mailTos)->setBody($messageBody); if ($attachedFile) { $message->attach(\Swift_Attachment::fromPath($attachedFile)); } if ($smtpSsl) { $transport = Swift_SmtpTransport::newInstance($smtpHost, $smtpPort, 'ssl'); } else { $transport = Swift_SmtpTransport::newInstance($smtpHost, $smtpPort); } $transport->setUsername($smtpUser)->setPassword($smtpPass); $mailer = Swift_Mailer::newInstance($transport); // Send the message $result = $mailer->send($message); if ($result) { header("Location: " . get_site_url(NULL, 'contact') . '?contact-message-sent=1'); exit; } } catch (\Exception $e) { throw $e; } }
public function mail(CategoryEvent $event) { /** @var BaseHandler $handler */ $handler = $event->getParam('handler'); if ($handler) { $dateFormat = 'Y-m-d h:i:s'; $mailer = new Mailer(); $mailer->setGroup('product'); $message = $mailer->getMessage(); $message->setSubject($handler->getUrl() . ' ' . date($dateFormat)); $body = 'Script started at: ' . date($dateFormat, $this->registry->startTime) . PHP_EOL; $body .= 'Script finished at: ' . date($dateFormat) . '; Total execute time: ' . date('i:s', time() - $this->registry->startTime) . PHP_EOL; $body .= 'Parsed urls: ' . $handler->getJobTotal() . PHP_EOL; $message->setBody($body); $fileParts = pathinfo($this->config->getParseDir() . $handler->getFileName()); $fname = $this->config->getParseDir() . $handler->getFileName(); file_exists($fname) ? $message->attach(\Swift_Attachment::fromPath($fname)) : null; $fname = $this->config->getParseDir() . $fileParts['filename'] . '_disappeared_products.' . $fileParts['extension']; file_exists($fname) ? $message->attach(\Swift_Attachment::fromPath($fname)) : null; $fname = $this->config->getParseDir() . $fileParts['filename'] . '_newProducts.' . $fileParts['extension']; file_exists($fname) ? $message->attach(\Swift_Attachment::fromPath($fname)) : null; $fname = $this->config->getParseDir() . $fileParts['filename'] . '_recently_reviewed_products.' . $fileParts['extension']; file_exists($fname) ? $message->attach(\Swift_Attachment::fromPath($fname)) : null; $mailer->send(); } }
public function testAttachmentSending() { $mailer = $this->_getMailer(); $message = Swift_Message::newInstance()->setCharset('utf-8')->setSubject('[Swift Mailer] InternationalSmokeTest (διεθνής)')->setFrom(array(SWIFT_SMOKE_EMAIL_ADDRESS => 'Χριστοφορου (Swift Mailer)'))->setTo(SWIFT_SMOKE_EMAIL_ADDRESS)->setBody('This message should contain an attached ZIP file (named "κείμενο, εδάφιο, θέμα.zip").' . PHP_EOL . 'When unzipped, the archive should produce a text file which reads:' . PHP_EOL . '"This is part of a Swift Mailer v4 smoke test."' . PHP_EOL . PHP_EOL . 'Following is some arbitrary Greek text:' . PHP_EOL . 'Δεν βρέθηκαν λέξεις.')->attach(Swift_Attachment::fromPath($this->_attFile)->setContentType('application/zip')->setFilename('κείμενο, εδάφιο, θέμα.zip')); $this->assertEqual(1, $mailer->send($message), '%s: The smoke test should send a single message'); $this->_visualCheck('http://swiftmailer.org/smoke/4.0.0/international.jpg'); }
protected function _mapToSwift(SendGrid\Email $mail) { $message = new \Swift_Message($mail->getSubject()); /* * Since we're sending transactional email, we want the message to go to one person at a time, rather * than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers * but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be * ignored anyway. */ $message->setTo($mail->to); $message->setFrom($mail->getFrom(true)); $message->setCc($mail->getCcs()); $message->setBcc($mail->getBccs()); if ($mail->getHtml()) { $message->setBody($mail->getHtml(), 'text/html'); if ($mail->getText()) { $message->addPart($mail->getText(), 'text/plain'); } } else { $message->setBody($mail->getText(), 'text/plain'); } if ($replyto = $mail->getReplyTo()) { $message->setReplyTo($replyto); } $attachments = $mail->getAttachments(); //add any attachments that were added if ($attachments) { foreach ($attachments as $attachment) { $message->attach(\Swift_Attachment::fromPath($attachment['file'])); } } $message_headers = $message->getHeaders(); $message_headers->addTextHeader("x-smtpapi", $mail->smtpapi->jsonString()); return $message; }
public function sendEmail($to, $cc, $bcc, $replay, $body, $nombreArchivos, $asunto) { $email = \Swift_Message::newInstance(); $email->setContentType('text/html'); $email->setFrom($this->from, 'La Plus Belle y Sonodigest'); $email->setTo($to); foreach ($nombreArchivos as $key => $nombre) { $email->attach(\Swift_Attachment::fromPath('http://190.53.176.116/laplusbelle/Photos/correos/' . $nombre)); } if ($cc != null) { $email->setCc($cc); } if ($replay != null) { $email->setReplyTo($replay); } else { $email->setReplyTo('*****@*****.**'); } if ($bcc != null) { $email->setBcc($bcc); } //$email->setSubject($this->subject); $email->setSubject($asunto); $email->setBody($body); $this->mail->send($email); }
/** * Méthode d'envoie d'email * * @param array $data * @param array|array<UserInterface> $aEmailTo * @param array $aAttachement */ protected function send($data, $aEmailTo, $aAttachement = array(), MailParametersInterface $mailParameters) { $mailerForSend = $this->mailer; foreach ($aEmailTo as $user) { //Create the message /* @var $message \Swift_Message */ $message = \Swift_Message::newInstance()->setSubject($data['objet'])->setFrom(array($this->config['from_email']['address'] => $this->config['from_email']['sender_name'])); foreach ($aAttachement as $oneAttachment) { $attachment = \Swift_Attachment::newInstance($oneAttachment['content'], $oneAttachment['name'], $oneAttachment['type']); $message->attach($attachment); } $failedRecipients = array(); $numSent = 0; if (is_object($user) && method_exists($user, 'getEmail')) { $message->setTo($user->getEmail()); } elseif (is_string($user)) { $message->setTo($user); } else { throw new \RuntimeException('Invalid email'); } $message->setBody($this->templating->render($this->getTemplateDirectory($mailParameters) . ':Mails:' . $data['template'] . '.html.twig', $data), "text/html"); $message->addPart($this->templating->render($this->getTemplateDirectory($mailParameters) . ':Mails:' . $data['template'] . '.txt.twig', $this->getRaw($data)), "text/plain"); $numSent += $mailerForSend->send($message, $failedRecipients); if ($this->logger && $this->config['active_log'] === true) { $this->logger->info(sprintf("Email: '%s' sended to: '%s'", $data['objet'], current(array_keys($message->getTo()))), array('CnertaMailingBundle', 'email-sended')); } } return $numSent; }
public function sendMail($subject, $body, $filePath = null, $viaSpool = false) { $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->config['from'])->setTo($this->config['to'])->setBody($body); if (!empty($filePath)) { $message->attach(\Swift_Attachment::fromPath($filePath)); } return $this->mailer->send($message); }
public function buildPreAttachements() { if (is_array($this->email->getPreAttachements())) { foreach ($this->email->getPreAttachements() as $attach) { $this->getMail()->attach(\Swift_Attachment::fromPath($attach->getPathname())); } } }
public function createParticipation($user, $drink) { $dDrink = \Datetime::createFromFormat('Y-m-d H:i:s', $drink['day'] . ' ' . $drink['hour']); $dEndDrink = clone $dDrink; $dEndDrink->modify('+3 hours'); $dateFormat = 'Ymd\\THis'; $icsInvite = \Swift_Attachment::newInstance()->setContentType('text/calendar;charset=UTF-8;method=REQUEST')->setBody($this->twig->render('drink/invite_ics.twig', array('user' => $user, 'drink' => $drink, 'datetimes' => array('start' => $dDrink->format($dateFormat), 'end' => $dEndDrink->format($dateFormat), 'current' => date($dateFormat)))))->setEncoder(\Swift_Encoding::getQpEncoding()); return $this->mailer->createMessage()->setSubject('[Aperophp.net] Inscription à un ' . $drink['kind'])->setFrom(array('*****@*****.**'))->setTo(array($user['email']))->setBody($this->twig->render('drink/participation_mail.html.twig', array('user' => $user, 'drink' => $drink)), 'text/html')->attach($icsInvite); }
public function mail($to, $subject, $body, $attach = null) { $mailer = $this->mailer; $message = $mailer->createMessage()->setSubject($subject)->setTo($to)->setFrom($this->mailer_user)->setBody($body, 'text/html'); if ($attach) { $message->attach(\Swift_Attachment::fromPath($attach)); } $mailer->send($message); }
public function testNonEmptyFileNameAsAttachement() { $message = new Swift_Message(); try { $message->attach(Swift_Attachment::fromPath(__FILE__)); } catch (Exception $e) { $this->fail('Path should not be empty'); } }
/** * Send a message * * @param string $subject * @param string $body */ public function send($subject, $body) { if ($this->mailer) { $message = \Swift_Message::newInstance($subject)->setBody($body)->addTo($this->to)->setFrom($this->from)->attach(\Swift_Attachment::fromPath($this->logPath)->setDisposition('inline')); $this->mailer->send($message); } }