add verify mail and email address saving
parent
0b9873ef7b
commit
dd579b3513
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Eater\Glim\Service;
|
||||
|
||||
use Eater\Glim\Model\EmailMessage;
|
||||
use Eater\Glim\Model\User as UserModel;
|
||||
use Nette\Mail\IMailer;
|
||||
use Nette\Mail\Message;
|
||||
|
||||
class Mail extends Main
|
||||
{
|
||||
/**
|
||||
* @param UserModel $user
|
||||
* @param string $template
|
||||
* @param array $context
|
||||
*/
|
||||
public function sendFromSystem(UserModel $user, $template, $context)
|
||||
{
|
||||
$message = $this->createEmailMessage($template, $context);
|
||||
$message->setRecipientEmailAddress($user->getEmailAddressRelatedByEmail());
|
||||
$message->save();
|
||||
|
||||
$this->sendEmailMessage($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
* @param array $context
|
||||
* @return EmailMessage
|
||||
*/
|
||||
public function createEmailMessage($template, $context) {
|
||||
$message = new EmailMessage();
|
||||
|
||||
/** @var \Twig_Environment $twig */
|
||||
$twig = $this->get('twig');
|
||||
|
||||
$txt = $twig->render($template, $context);
|
||||
|
||||
list($subject, $contents) = explode('===', $txt);
|
||||
|
||||
$message->setSubject(trim($subject));
|
||||
$message->setContents(trim($contents));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailMessage $emailMessage
|
||||
*/
|
||||
public function sendEmailMessage(EmailMessage $emailMessage)
|
||||
{
|
||||
$mail = new Message();
|
||||
$mail->setSubject($emailMessage->getSubject());
|
||||
$mail->setBody($emailMessage->getContents());
|
||||
$mail->setFrom($emailMessage->getSenderEmail(), $emailMessage->getSenderName());
|
||||
$mail->setReturnPath($emailMessage->getSenderEmail());
|
||||
|
||||
$mail->addTo($emailMessage->getRecipientEmail(), $emailMessage->getRecipientName());
|
||||
/** @var IMailer $sender */
|
||||
$sender = $this->get('mail-sender');
|
||||
|
||||
$sender->send($mail);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: eater
|
||||
* Date: 6/29/16
|
||||
* Time: 1:15 AM
|
||||
*/
|
||||
|
||||
namespace Eater\Glim\Service;
|
||||
|
||||
|
||||
use Eater\Glim\Core;
|
||||
use Nette\Mail\IMailer;
|
||||
use Nette\Mail\SendmailMailer;
|
||||
use Nette\Mail\SmtpMailer;
|
||||
use Slim\Container;
|
||||
|
||||
class MailSender
|
||||
{
|
||||
/**
|
||||
* @param Container $c
|
||||
* @param string $name
|
||||
* @return IMailer
|
||||
*/
|
||||
static public function init($c, $name) {
|
||||
/** @var Core $core */
|
||||
$core = $c->get('core');
|
||||
$config = $core->getConfig();
|
||||
|
||||
if ($config->get('mail.type', 'sendmail') === 'smtp') {
|
||||
return new SmtpMailer([
|
||||
'host' => $config->get('mail.host', 'localhost'),
|
||||
'secure' => $config->get('mail.secure'),
|
||||
'username' => $config->get('mail.username'),
|
||||
'password' => $config->get('mail.password'),
|
||||
]);
|
||||
} else {
|
||||
return new SendmailMailer();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
Verify your Zer.ooo account: {{ username }}
|
||||
===
|
||||
Hey {{ username }},
|
||||
|
||||
You successfully created an account on Zer.ooo, please click on the following link to verify your account.
|
||||
|
||||
{{ verificationLink }}
|
||||
|
||||
Kind regards,
|
||||
|
||||
The Zer.ooo team
|
Loading…
Reference in New Issue