function sendFormSucceeded(\Nette\Forms\BootstrapUIForm $form) { $helpdesk = $this->database->table("helpdesk")->get(1); $helpdesk_admin = $helpdesk->related("helpdesk_emails", "helpdesk_id")->get(1); $helpdesk_customer = $helpdesk->related("helpdesk_emails", "helpdesk_id")->get(2); $arr = array("subject" => $form->values->name, "email" => $form->values->email, "message" => $form->values->message, "ipaddress" => getenv('REMOTE_ADDR'), "helpdesk_id" => 1, 'date_created' => date("Y-m-d H:i"), 'session_id' => session_id()); if ($this->presenter->user->isLoggedIn()) { $arr["users_id"] = $this->presenter->template->member->id; } if ($helpdesk->fill_phone > 0) { $arr["phone"] = $form->values->phone; } $this->database->table("helpdesk_messages")->insert($arr); $params = array('name' => $form->values->name, 'email' => $form->values->email, 'phone' => $form->values->phone, 'message' => $form->values->message, 'ipaddress' => getenv('REMOTE_ADDR'), 'time' => date("Y-m-d H:i"), 'settings' => $this->presenter->template->settings); $latte = new \Latte\Engine(); $latte->setLoader(new Latte\Loaders\StringLoader()); //$latte->setTempDirectory(__DIR__ . '/../temp'); $email_admin = $latte->renderToString($helpdesk_admin->body, $params); $email_customer = (string) $latte->renderToString($helpdesk_customer->body, $params); $mail = new \Nette\Mail\Message(); $mail->setFrom($this->presenter->template->settings["contacts:email:hq"]); $mail->addTo($this->presenter->template->settings["contacts:email:hq"]); $mail->setHTMLBody($email_customer); $mailA = new \Nette\Mail\Message(); $mailA->setFrom($this->presenter->template->settings["contacts:email:hq"]); $mailA->addTo($form->values->email); $mailA->setHTMLBody($email_admin); $mailer = new \Nette\Mail\SendmailMailer(); $mailer->send($mail); $mailer->send($mailA); $this->presenter->flashMessage($this->presenter->translator->translate('messages.sign.thanksForMessage'), "error"); $this->presenter->redirect(":Front:Contact:default"); }
public function send($to, $message, $args = []) { $mail = new \Nette\Mail\Message(); $mail->setFrom($this->config['from'], $this->config['display']); $mail->addTo($to); $dir = $this->config['templateDir']; $template = new \Nette\Templating\FileTemplate(); $template->registerFilter(new \Nette\Latte\Engine()); $template->registerHelperLoader('\\Nette\\Templating\\Helpers::loader'); $template->setFile($dir . '/' . $message . '.latte'); $template->setParameters($args); $template->recipient = $to; $mail->setHtmlBody($template); $this->mailer->send($mail); }
protected function execute(InputInterface $input, OutputInterface $output) { $message = new \Nette\Mail\Message(); if (!$this->validateEmail($from = trim($input->getOption('from')))) { $output->writeln('<error>Expected valid email address, given "' . $from . '"</error>'); return 1; } $message->setFrom($from); if (!$this->validateEmail($to = trim($input->getArgument('recipient')))) { $output->writeln('<error>Expected valid email address, given "' . $to . '"</error>'); return 1; } $message->addTo($to); $message->setSubject($input->getOption('subject')); $message->setBody($input->getOption('message')); if ($input->getOption('force') && $this->mailer instanceof \Simplement\MailQueue\Mailer) { $this->mailer->send($message, 1, FALSE); } else { $this->mailer->send($message); } }
/** * @param null|string $message * @return \Nette\Mail\Message */ protected function getCopyMail($message = NULL) { $values = $this['form']['_inputs']->getValues(); $mail = new \Nette\Mail\Message(); $mail->setFrom($this->mailformEntity->emails[0], $this->mailformEntity->recipient); $mail->addTo($values['_email'], $values['_name']); $mail->setSubject($this->mailformEntity->subject); $mail->setBody($message ? $message : $this->getCopyMessage()); return $mail; }
function send(\xepan\communication\Model_Communication_EmailSetting $email_setting, $mailer = null) { $this['status'] = 'Outbox'; $this['direction'] = 'Out'; $this['mailbox'] = $email_setting['email_username'] . '#SENT'; $this['description'] = $this['description'] . $email_setting['signature']; if (!$this['to_id']) { $this->findContact('to'); } $this['communication_channel_id'] = $email_setting->id; if (!$this->app->getConfig('test_mode', false)) { try { $mail = new \Nette\Mail\Message(); $mail->setFrom($this['from_raw']['email'], $this['from_raw']['name'] ?: null); $return_path = $email_setting['return_path']; if (!$return_path) { $return_path = $this['from_raw']['email']; } $mail->setReturnPath($return_path); foreach ($this['to_raw'] as $to) { $mail->addTo(trim($to['email']), $to['name'] ?: null); } if ($this['cc_raw']) { foreach ($this['cc_raw'] as $cc) { $mail->addCC(trim($cc['email']), $cc['name'] ?: null); } } if ($this['bcc_raw']) { foreach ($this['bcc_raw'] as $bcc) { $mail->addBcc(trim($bcc['email']), $bcc['name'] ?: null); } } foreach ($this->getAttachments() as $attach) { $mail->addAttachment($_SERVER["DOCUMENT_ROOT"] . $attach); } $mail->setSubject($this['title'])->setHTMLBody($this['description'], $this->app->pathfinder->base_location->base_path); if (!$mailer) { if (isset($this->app->mailer)) { $mailer = $this->app->mailer; } else { $mailer = new \Nette\Mail\SmtpMailer(array('host' => $email_setting['email_host'], 'username' => $email_setting['email_username'], 'password' => $email_setting['email_password'], 'secure' => $email_setting['encryption'], 'persistent' => true)); $this->app->mailer = $mailer; } } $mailer->send($mail); $email_setting['last_emailed_at'] = $this->app->now; $email_setting['email_sent_in_this_minute'] = $email_setting['email_sent_in_this_minute'] + 1; $email_setting->save(); } catch (\Exception $e) { $this->save(); throw $e; } } if ($this->app->getConfig('test_mode', false)) { // echo "setting last_emailed_at on ". $email_setting['name']. ' as '. $this->app->now . '<br/>'; $email_setting['last_emailed_at'] = $this->app->now; $email_setting['email_sent_in_this_minute'] = $email_setting['email_sent_in_this_minute'] + 1; $email_setting->save(); } $this['status'] = 'Sent'; $this->save(); }
foreach ($article_arr as $i => $article) { if ($article['content'] == "") { continue; } $content = new Develpr\Phindle\Content(); $content->setTitle($article['title']); $content->setHtml('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">' . "<h3>{$article['title']}</h3>" . $article['content']); $content->setPosition($i); $phindle->addContent($content); } $phindle->process(); $ebook_path = $phindle->getMobiPath(); $mail = new Nette\Mail\Message(); $mail->setFrom(sprintf('%s <%s>', $config['KD_SENDER']['from'], $config['KD_SENDER']['username']))->setSubject($phindle->getAttribute('title'))->addAttachment($ebook_path, null, 'application/octet-stream'); foreach ($config['KD_RECEIVER'] as $receiver) { $mail->addTo($receiver); } $mailer = new Nette\Mail\SmtpMailer($config['KD_SENDER']); $result = $mailer->send($mail); //获取图片本地存储路径 function get_image_filename($url, $local_prefix = "") { $arr = parse_url($url); $basename = basename($arr['path']); if (strpos($basename, '.') === false) { return $local_prefix . $basename . '.jpg'; } else { return $local_prefix . $basename; } } //下载图片
public function sendEmail() { $model = $this->createGridModel(); $items = $model->getItems(); $values = $this['email']->values; foreach ($items as $riesitel) { try { $mail = new \Nette\Mail\Message(); $mail->setFrom('*****@*****.**'); $mail->addTo($riesitel['email']); $mail->setSubject($values['subject']); $mail->setBody($values['body']); $mail->send(); } catch (\Exception $e) { $this['grid']->flashMessage($e->getMessage()); } } $this->redirect('this'); }