Author: Chris Corbyn
Inheritance: extends Swift_Mime_SimpleMessage
 /**
  * Fills in message using blocks from a template (`body`, `subject`, `from`).
  * If there is no `body` block then whole template will be used.
  * If there is no `subject` or `from` block then corresponding default value will be used.
  * @param \Swift_Message $message
  * @param \Twig_Template $templateContent
  * @param array $data
  */
 protected function populateMessage(\Swift_Message $message, \Twig_Template $templateContent, $data)
 {
     $body = $templateContent->hasBlock('body') ? $templateContent->renderBlock('body', $data) : $templateContent->render($data);
     $subject = $templateContent->hasBlock('subject') ? $templateContent->renderBlock('subject', $data) : $this->defaultSubject;
     $from = $templateContent->hasBlock('from') ? $templateContent->renderBlock('from', $data) : $this->defaultFrom;
     $message->setFrom($from)->setSubject($subject)->setBody($body, 'text/html', 'utf-8');
 }
示例#2
0
 public function sendEmail($recipient_name, $recipient_email, $subject, $body)
 {
     //$subject = 'Hello from Mandrill, PHP!';
     $from = array($this::SENDER_EMAIL => $this::SENDER_NAME);
     $to = array($recipient_email => $recipient_name);
     //$text = "Mandrill speaks plaintext";
     //$html = "<em>Mandrill speaks <strong>HTML</strong></em>";
     $transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
     $transport->setUsername($this::MANDRILL_USERNAME);
     $transport->setPassword($this::MANDRILL_PASSWORD);
     $swift = Swift_Mailer::newInstance($transport);
     $message = new Swift_Message($subject);
     $message->setFrom($from);
     //$message->setBody($html, 'text/html');
     $message->setTo($to);
     $message->addPart($body, 'text/plain');
     $failures = '';
     if ($recipients = $swift->send($message, $failures)) {
         echo 'Message successfully sent!';
         return true;
     } else {
         echo "There was an error:\n";
         print_r($failures);
         return false;
     }
 }
 private function sendMessage(InterestEvent $event)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Vente réussie à modifier SoldSuccessListener", $templating->render('SnoozitSkuagBundle:Mail/Interest:InterestedMail.html.twig', array('slug' => $event->getAdvertSlug(), 'id' => $event->getAdvertId(), 'title' => $event->getAdvertTitle(), 'userInterested' => $event->getCustomerUsername(), 'ownername' => $event->getOwnerUsername())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
示例#4
0
文件: Mailer.php 项目: citco/mailer
 /**
  * Send a Swift Message instance.
  *
  * @param  \Swift_Message  $message
  * @return int
  */
 protected function sendSwiftMessage($message)
 {
     $from = $message->getFrom();
     if (empty($from)) {
         list($sender_addr, $sender_name) = $this->sender_addr;
         empty($sender_addr) or $message->setFrom($sender_addr, $sender_name);
     }
     list($log_addr, $log_name) = $this->log_addr;
     empty($log_addr) or $message->setBcc($log_addr, $log_name);
     $to = $message->getTo();
     empty($to) or $to = key($to);
     /*
      * Set custom headers for tracking
      */
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-Site-ID', $this->x_site_id);
     $headers->addTextHeader('X-User-ID', base64_encode($to));
     /*
      * Set to address based on environment
      */
     if (strcasecmp($this->environment, 'production') != 0) {
         list($dev_addr, $dev_name) = $this->developer_addr;
         $message->setTo($dev_addr, $dev_name);
     }
     /*
      * Set return path.
      */
     if ($this->return_path) {
         $return_path = $this->generateReturnPathEmail(key($message->getTo()));
         $message->setReturnPath($return_path);
     }
     parent::sendSwiftMessage($message);
 }
示例#5
0
 /**
  * @param $cname     string       Config key from config/email.php
  * @param $subject   string       Message subject
  * @param $body      string       Message body
  * @param $from      string|array From single address (for example '*****@*****.**' or array('*****@*****.**' => 'John Doe'))
  * @param $to        string|array To single address (for example '*****@*****.**' or array('*****@*****.**' => 'John Doe'))
  * @param $mime_type string       Message MIME type, default value text/plain
  * @param $charset   string       Message character set, default value UTF-8
  * 
  * @return int Result code
  */
 public static function send($cname, $subject, $body, $from, $to, $mime_type = 'text/plain', $charset = 'utf-8')
 {
     $mailer = self::instance($cname);
     $message = new Swift_Message($subject, $body, $mime_type, $charset);
     $message->setFrom($from)->setTo($to);
     return $mailer->send($message);
 }
 /**
  * Create activity from Swift Message
  * @param  \Swift_Message $message 
  * @return EmailActivity
  */
 protected function createActivity(\Swift_Message $message)
 {
     // Creation du doc de trace d'activité avec les données basiques
     $from_email = $message->getHeaders()->get('From')->getFieldBody();
     $to_email = $message->getHeaders()->get('To')->getFieldBody();
     $message_id = $message->getHeaders()->get('Message-ID')->getId();
     $subject = $message->getSubject();
     $activity = new $this->activity_class();
     $activity->setFromEmail($from_email);
     $activity->setToEmail($to_email);
     $activity->setSubject($subject);
     $activity->setMessageId($message_id);
     // Récupération du document associé aux relations from_user et to_user
     $meta = $this->dm->getClassMetadata($this->activity_class);
     $class = $meta->getAssociationTargetClass('from_user');
     $repo = $this->dm->getRepository($class);
     $user = $repo->findOneByEmail($activity->getFromEmail());
     if (!is_null($user)) {
         $activity->setFromUser($user);
     }
     $class = $meta->getAssociationTargetClass('to_user');
     $repo = $this->dm->getRepository($class);
     $user = $repo->findOneByEmail($activity->getToEmail());
     if (!is_null($user)) {
         $activity->setToUser($user);
     }
     return $activity;
 }
示例#7
0
 public function executePassword()
 {
     $this->form = new RequestPasswordForm();
     if ($this->getRequest()->isMethod('get')) {
         return;
     }
     $this->form->bind($this->getRequest()->getParameter('form'));
     if (!$this->form->isValid()) {
         return;
     }
     $email = $this->form->getValue('email');
     $password = substr(md5(rand(100000, 999999)), 0, 6);
     $sfGuardUserProfile = sfGuardUserProfilePeer::retrieveByEmail($email);
     $sfGuardUser = $sfGuardUserProfile->getSfGuardUser();
     $sfGuardUser->setPassword($password);
     try {
         $connection = new Swift_Connection_SMTP('mail.sis-nav.com', 25);
         $connection->setUsername('*****@*****.**');
         $connection->setPassword('gahve123');
         $mailer = new Swift($connection);
         $message = new Swift_Message('Request Password');
         $mailContext = array('email' => $email, 'password' => $password, 'username' => $sfGuardUser->getUsername(), 'full_name' => $sfGuardUserProfile->getFirstName());
         $message->attach(new Swift_Message_Part($this->getPartial('mail/requestPasswordHtmlBody', $mailContext), 'text/html'));
         $message->attach(new Swift_Message_Part($this->getPartial('mail/requestPasswordTextBody', $mailContext), 'text/plain'));
         $mailer->send($message, $email, '*****@*****.**');
         $mailer->disconnect();
     } catch (Exception $e) {
         $mailer->disconnect();
     }
     $sfGuardUser->save();
     $this->getUser()->setFlash('info', 'A new password is sent to your email.');
     $this->forward('site', 'message');
 }
 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;
 }
 /**
  * @When I send email to :email with message :body
  */
 public function iSendEmailWithMessage($email, $body)
 {
     $message = new \Swift_Message('Subject', $body);
     $message->setSender('*****@*****.**');
     $message->setTo($email);
     $this->sendEmail($message);
 }
示例#10
0
 private function sendMessage(FollowUserEvent $event)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Vous avez une nouvel abonné!", $templating->render('SnoozitSkuagBundle:Mail/Follow:UserFollowed.html.twig', array('followerUserName' => $event->getUser()->getUsername())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 public function testBeforeSendPerformedWithDisabledPlugin()
 {
     $this->plugin->setEnabled(false);
     $this->message->expects($this->never())->method('embed');
     $this->message->expects($this->never())->method('setBody');
     $this->plugin->beforeSendPerformed($this->event);
 }
示例#12
0
文件: Digest.php 项目: woyifang/forum
 /**
  * Sends the digest
  */
 public function send()
 {
     $lastMonths = new \DateTime();
     $lastMonths->modify('-6 month');
     $parameters = array('modified_at >= ?0 AND digest = "Y" AND notifications <> "N"', 'bind' => array($lastMonths->getTimestamp()));
     $users = array();
     foreach (Users::find($parameters) as $user) {
         if ($user->email && strpos($user->email, '@') !== false && strpos($user->email, '@users.noreply.github.com') === false) {
             $users[trim($user->email)] = $user->name;
         }
     }
     $fromName = $this->config->mail->fromName;
     $fromEmail = $this->config->mail->fromEmail;
     $url = $this->config->site->url;
     $subject = 'Top Stories from Phosphorum ' . date('d/m/y');
     $lastWeek = new \DateTime();
     $lastWeek->modify('-1 week');
     $order = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - ' . 'IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies + IF(accepted_answer = "Y", 10, 0) DESC';
     $parameters = array('created_at >= ?0 AND deleted != 1 AND categories_id <> 4', 'bind' => array($lastWeek->getTimestamp()), 'order' => $order, 'limit' => 10);
     $e = $this->escaper;
     $content = '<html><head></head><body><p><h1 style="font-size:22px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;padding:16px 0;border-bottom:1px solid #e2e2e2">Top Stories from Phosphorum</h1></p>';
     foreach (Posts::find($parameters) as $post) {
         $user = $post->user;
         if ($user == false) {
             continue;
         }
         $content .= '<p><a style="text-decoration:none;display:block;font-size:20px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">' . $e->escapeHtml($post->title) . '</a></p>';
         $content .= '<p><table width="100%"><td><table><tr><td>' . '<img src="https://secure.gravatar.com/avatar/' . $user->gravatar_id . '?s=32&amp;r=pg&amp;d=identicon" width="32" height="32" alt="' . $user->name . ' icon">' . '</td><td><a style="text-decoration:none;color:#155fad" href="' . $url . '/user/' . $user->id . '/' . $user->login . '">' . $user->name . '<br><span style="text-decoration:none;color:#999;text-decoration:none">' . $user->getHumanKarma() . '</span></a></td></tr></table></td><td align="right"><table style="border: 1px solid #dadada;" cellspacing=5>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Created</label><br>' . $post->getHumanCreatedAt() . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Replies</label><br>' . $post->number_replies . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Views</label><br>' . $post->number_views . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Votes</label><br>' . ($post->votes_up - $post->votes_down) . '</td>' . '</tr></table></td></tr></table></p>';
         $content .= $this->markdown->render($e->escapeHtml($post->content));
         $content .= '<p><a style="color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">Read more</a></p>';
         $content .= '<hr style="border: 1px solid #dadada">';
     }
     $textContent = strip_tags($content);
     $htmlContent = $content . '<p style="font-size:small;-webkit-text-size-adjust:none;color:#717171;">';
     $htmlContent .= PHP_EOL . 'This email was sent by Phalcon Framework. Change your e-mail preferences <a href="' . $url . '/settings">here</a></p>';
     foreach ($users as $email => $name) {
         try {
             $message = new \Swift_Message('[Phalcon Forum] ' . $subject);
             $message->setTo(array($email => $name));
             $message->setFrom(array($fromEmail => $fromName));
             $bodyMessage = new \Swift_MimePart($htmlContent, 'text/html');
             $bodyMessage->setCharset('UTF-8');
             $message->attach($bodyMessage);
             $bodyMessage = new \Swift_MimePart($textContent, 'text/plain');
             $bodyMessage->setCharset('UTF-8');
             $message->attach($bodyMessage);
             if (!$this->transport) {
                 $this->transport = \Swift_SmtpTransport::newInstance($this->config->smtp->host, $this->config->smtp->port, $this->config->smtp->security);
                 $this->transport->setUsername($this->config->smtp->username);
                 $this->transport->setPassword($this->config->smtp->password);
             }
             if (!$this->mailer) {
                 $this->mailer = \Swift_Mailer::newInstance($this->transport);
             }
             $this->mailer->send($message);
         } catch (\Exception $e) {
             echo $e->getMessage(), PHP_EOL;
         }
     }
 }
示例#13
0
 public function respond(array $communication, \stdClass $msg)
 {
     $result = $this->generateResponse($communication);
     if (preg_match('/^\\s*re:/', $msg->subject)) {
         $subject = $msg->subject;
     } else {
         $subject = 'Re: ' . $msg->subject;
     }
     if (isset($this->config['name'])) {
         $from = array($this->config['email_address'] => $this->config['name']);
     } else {
         $from = array($this->config['email_address']);
     }
     $to = array($msg->from_email);
     if (isset($msg->headers->{'Message-Id'})) {
         $message_id = $msg->headers->{'Message-Id'};
     } else {
         $message_id = false;
     }
     // TODO - set reply to id
     $transport = \Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
     $transport->setUsername($this->config['mandrill_username']);
     $transport->setPassword($this->config['mandrill_password']);
     $swift = \Swift_Mailer::newInstance($transport);
     $message = new \Swift_Message($subject);
     $message->setFrom($from);
     $message->setBody($result);
     $message->setTo($to);
     $result = $swift->send($message);
 }
 private function sendGuestMessage(InterestEvent $event)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Désistement sur votre annonce!", $templating->render('SnoozitSkuagBundle:Mail/Interest:UnInterestedMail.html.twig', array('slug' => $event->getAdvertSlug(), 'id' => $event->getAdvertId(), 'title' => $event->getAdvertTitle(), 'userInterested' => $event->getCustomerUsername(), 'ownername' => $event->getGuestOwnerName())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 private function sendMessage(User $user)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Snoozit vous souhaite la bienvenue!", $templating->render('SnoozitSkuagBundle:Mail/Registration:RegistrationMail.html.twig', array('user' => $user->getUsername())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
示例#16
0
 private function sendMessage(NegoceEvent $event)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Vous avez reçu une offre!", $templating->render('SnoozitSkuagBundle:Mail/Negoce:NegoceMail.html.twig', array('slug' => $event->getAdvertSlug(), 'id' => $event->getAdvertId(), 'title' => $event->getAdvertTitle(), 'userInterested' => $event->getCustomerUsername(), 'ownername' => $event->getOwnerUsername(), 'price' => $event->getPrice())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 /**
  * @inheritDoc
  */
 public static function fromWrappedMessage(MailWrappedMessage $wrappedMessage = null, $transport = null)
 {
     if (!$wrappedMessage instanceof MailWrappedMessage) {
         throw new MailWrapperSetupException('Not MailWrappedMessage');
     }
     $message = new \Swift_Message();
     foreach ($wrappedMessage->getToRecipients() as $address) {
         $message->addTo($address);
     }
     foreach ($wrappedMessage->getCcRecipients() as $address) {
         $message->addCc($address);
     }
     foreach ($wrappedMessage->getBccRecipients() as $address) {
         $message->addBcc($address);
     }
     $message->setReplyTo($wrappedMessage->getReplyTo());
     $message->setFrom($wrappedMessage->getFrom());
     $message->setSubject($wrappedMessage->getSubject());
     if ($wrappedMessage->getContentText()) {
         $message->setBody($wrappedMessage->getContentText());
     }
     if ($wrappedMessage->getContentHtml()) {
         $message->setBody($wrappedMessage->getContentHtml(), 'text/html');
     }
     return $message;
 }
示例#18
0
 public function send(\Swift_Message $message)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
     curl_setopt($ch, CURLOPT_URL, $this->host);
     //不同于登录SendCloud站点的帐号,您需要登录后台创建发信子帐号,使用子帐号和密码才可以进行邮件的发送。
     $from = $message->getFrom();
     $to = '';
     foreach ($message->getTo() as $_mail => $_toName) {
         if ($to .= '') {
             $to .= ';';
         }
         $to .= $_mail;
     }
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('api_user' => $this->username, 'api_key' => $this->password, 'from' => $this->username, 'fromname' => is_array($from) ? current($from) : $from, 'to' => $to, 'subject' => $message->getSubject(), 'html' => $message->getBody())));
     $result = curl_exec($ch);
     //请求失败
     if ($result === false) {
         throw new \Exception(curl_error($ch));
     }
     curl_close($ch);
     $ret = json_decode($result);
     p($result);
     if ($ret->message != 'success') {
         throw new \Exception($result);
     }
     return $result;
 }
示例#19
0
 /**
  * Creates a swift message from a ParsedMessage, handles defaults
  *
  * @param ParsedMessage $parsedMessage
  *
  * @return \Swift_Message
  */
 protected function transformMessage(ParsedMessage $parsedMessage)
 {
     $message = new \Swift_Message();
     if ($from = $parsedMessage->getFrom()) {
         $message->setFrom($from);
     }
     // handle to with defaults
     if ($to = $parsedMessage->getTo()) {
         $message->setTo($to);
     }
     // handle cc with defaults
     if ($cc = $parsedMessage->getCc()) {
         $message->setCc($cc);
     }
     // handle bcc with defaults
     if ($bcc = $parsedMessage->getBcc()) {
         $message->setBcc($bcc);
     }
     // handle reply to with defaults
     if ($replyTo = $parsedMessage->getReplyTo()) {
         $message->setReplyTo($replyTo);
     }
     // handle subject with default
     if ($subject = $parsedMessage->getSubject()) {
         $message->setSubject($subject);
     }
     // handle body, no default values here
     $message->setBody($parsedMessage->getMessageText());
     if ($parsedMessage->getMessageHtml()) {
         $message->addPart($parsedMessage->getMessageHtml(), 'text/html');
     }
     return $message;
 }
示例#20
0
 public function testBodySwap()
 {
     $message1 = new Swift_Message('Test');
     $html = Swift_MimePart::newInstance('<html></html>', 'text/html');
     $html->getHeaders()->addTextHeader('X-Test-Remove', 'Test-Value');
     $html->getHeaders()->addTextHeader('X-Test-Alter', 'Test-Value');
     $message1->attach($html);
     $source = $message1->toString();
     $message2 = clone $message1;
     $message2->setSubject('Message2');
     foreach ($message2->getChildren() as $child) {
         $child->setBody('Test');
         $child->getHeaders()->removeAll('X-Test-Remove');
         $child->getHeaders()->get('X-Test-Alter')->setValue('Altered');
     }
     $final = $message1->toString();
     if ($source != $final) {
         $this->fail("Difference although object cloned \n [" . $source . "]\n[" . $final . "]\n");
     }
     $final = $message2->toString();
     if ($final == $source) {
         $this->fail('Two body matches although they should differ' . "\n [" . $source . "]\n[" . $final . "]\n");
     }
     $id_1 = $message1->getId();
     $id_2 = $message2->getId();
     $this->assertEquals($id_1, $id_2, 'Message Ids differ');
     $id_2 = $message2->generateId();
     $this->assertNotEquals($id_1, $id_2, 'Message Ids are the same');
 }
示例#21
0
 /**
  * @param string|array $to
  * @param MailTemplate $template
  * @param array $data
  */
 private function send($to, MailTemplate $template, array $data = [])
 {
     $body = $this->render($template, $data);
     $message = new \Swift_Message($template->getSubject(), $body, "text/html", "utf8");
     $message->setFrom($this->sender);
     $message->setTo($to);
     $this->mailer->send($message);
 }
 private function sendInvitationEmail($subject, $name, $email, $body, $expert, $mailer)
 {
     $message = new Swift_Message();
     $message->setFrom('Expert bank');
     $message->setSubject($subject);
     $message->setBody("U hebt via de expertbank een bericht ontvangen van {$name} ({$email}):\n\n{$body}");
     $mailer->send($message, $expert->getEmail(), $email);
 }
 /**
  * Creates a DmSentMail from a Swift_Message
  * @param Swift_Message $message
  * @return DmSentMail
  */
 public function createFromSwiftMessage(Swift_Message $message)
 {
     $debug = $message->toString();
     if ($attachementPosition = strpos($debug, 'attachment; filename=')) {
         $debug = substr($debug, 0, $attachementPosition);
     }
     return $this->create(array('subject' => $message->getSubject(), 'body' => $message->getBody(), 'from_email' => implode(', ', array_keys((array) $message->getFrom())), 'to_email' => implode(', ', array_keys((array) $message->getTo())), 'cc_email' => implode(', ', array_keys((array) $message->getCC())), 'bcc_email' => implode(', ', array_keys((array) $message->getBCC())), 'reply_to_email' => implode(', ', array_keys((array) $message->getReplyTo())), 'sender_email' => implode(', ', array_keys((array) $message->getSender())), 'debug_string' => $debug));
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     // add your code here
     $blogs = Doctrine::getTable('Blog');
     $blogs_to_process = $blogs->findByIsThumbnail(0);
     foreach ($blogs_to_process as $blog) {
         $thumbalizr_url = 'http://api.thumbalizr.com?';
         $params = array('url' => $blog->url, 'width' => 300);
         $api_url = $thumbalizr_url . http_build_query($params);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $api_url);
         curl_setopt($ch, CURLOPT_HEADER, true);
         curl_setopt($ch, CURLOPT_NOBODY, true);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $res = curl_exec($ch);
         curl_close($ch);
         $res_tab = http_parse_headers($res);
         if (!empty($res_tab['X-Thumbalizr-Status']) && $res_tab['X-Thumbalizr-Status'] == 'OK') {
             // Image is ready let's store the URL!
             $image_data = file_get_contents($api_url);
             $path = sfConfig::get('app_image_path');
             $url = sfConfig::get('app_image_url');
             $image_name = md5($blog->url);
             echo $path . $image_name . "\n";
             file_put_contents($path . $image_name . '.jpg', $image_data);
             $blog->thumbnail_url = $image_name . '.jpg';
             $blog->is_thumbnail = 1;
             $blog->save();
             // Send mail to notify the blo will get into the game!
             try {
                 // Create the mailer and message objects
                 //$mailer = new Swift(new Swift_Connection_NativeMail());
                 //$connection = new Swift_Connection_SMTP('smtp.free.fr');
                 $connection = new Swift_Connection_NativeMail();
                 $mailer = new Swift($connection);
                 $message = new Swift_Message('Welcome!');
                 // Render message parts
                 $mailContext = array('admin_hash' => $blog->getAdmin_hash(), 'blog_url' => $blog->getUrl());
                 $v = $this->getPartial('newBlogMailHtmlBody', $mailContext);
                 $htmlPart = new Swift_Message_Part($v, 'text/html');
                 $message->attach($htmlPart);
                 $message->attach(new Swift_Message_Part($this->getPartial('newBlogMailTextBody', $mailContext), 'text/plain'));
                 $mailTo = $blog->getEmail();
                 $mailFrom = sfConfig::get('app_mail_webmaster');
                 $mailer->send($message, $mailTo, $mailFrom);
                 $mailer->disconnect();
             } catch (Exception $e) {
                 $this->logMessage($e);
             }
         } else {
             //print_r($res_tab);
         }
     }
 }
示例#25
0
 public function setGroup($name)
 {
     $mailTo = $this->mailerConfig->getMailToByGroupName($name);
     if ($mailTo) {
         $this->message->setTo($mailTo->getMailTo());
         return true;
     }
     return false;
 }
示例#26
0
 public function testNonEmptyFileNameAsAttachement()
 {
     $message = new Swift_Message();
     try {
         $message->attach(Swift_Attachment::fromPath(__FILE__));
     } catch (Exception $e) {
         $this->fail('Path should not be empty');
     }
 }
示例#27
0
 /**
  * Send the auth code to the user via email.
  *
  * @param TwoFactorInterface $user
  */
 public function sendAuthCode(TwoFactorInterface $user)
 {
     $template = $this->twig->loadTemplate('WallabagUserBundle:TwoFactor:email_auth_code.html.twig');
     $subject = $template->renderBlock('subject', []);
     $bodyHtml = $template->renderBlock('body_html', ['user' => $user->getName(), 'code' => $user->getEmailAuthCode(), 'support_url' => $this->supportUrl, 'wallabag_url' => $this->wallabagUrl]);
     $bodyText = $template->renderBlock('body_text', ['user' => $user->getName(), 'code' => $user->getEmailAuthCode(), 'support_url' => $this->supportUrl]);
     $message = new \Swift_Message();
     $message->setTo($user->getEmail())->setFrom($this->senderEmail, $this->senderName)->setSubject($subject)->setBody($bodyText, 'text/plain')->addPart($bodyHtml, 'text/html');
     $this->mailer->send($message);
 }
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof Application) {
         return;
     }
     $message = new \Swift_Message('Nouvelle candidature', 'Vous avez reçu une nouvelle candidature.');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
示例#29
0
 /**
  * в отправленном письме содержится нужный токен
  *
  * @depends testEmailSent
  */
 public function testSentEamilContainsRightToken(\Swift_Message $message)
 {
     /** @var User $user */
     $user = $this->getContainer()->get('fos_user.user_manager')->findUserByEmail('*****@*****.**');
     $this->assertContains('token', $message->getBody());
     preg_match('@\\?token=([^\\s]+)@', $message->getBody(), $matches);
     $this->assertCount(2, $matches);
     $token = $matches[1];
     $this->assertEquals($user->getConfirmationToken(), $token);
 }
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof Application) {
         return;
     }
     $message = new \Swift_Message("Nouvelle candidature", "Vous avez reçu une nouvelle candidature !");
     $message->addTo("*****@*****.**")->addFrom("*****@*****.**");
     $this->mailer->send($message);
 }