how to send message with validation link
Notice: This thread is very old.
- alnux
- Member | 139
Now i have the next error
Undefined variable: _control
<p>Para activar tu cuenta por favor haz click en <a href="<?php echo Latte\Runtime\Filters::escapeHtml($_control->link("//Homepage:validate", array('hash' => $auth_key)), ENT_COMPAT) ?>
php code is
$emailLatte = clone $presenter->getTemplate();
$emailmessage->htmlBody($emailLatte->getLatte()->renderToString($htmlfile,$this->params));
my latte template
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Registro</title>
</head>
<body>
<p>Hola {$username},</p>
<p>Para activar tu cuenta por favor haz click en <a href="{$auth_key_link}">este enlace</a> .</p>
<p>Para activar tu cuenta por favor haz click en <a n:href="//Homepage:validate hash => $auth_key">este enlace</a> .</p>
<p>Gracias y bienvenido a {$site_title}</p>
</body>
</html>
Last edited by alnux (2015-02-17 22:05)
- duke
- Member | 650
Problem is with this line:
$emailmessage->htmlBody($emailLatte->getLatte()->renderToString($htmlfile,$this->params));
… because you completely exclude parameters already defined in $emailLatte (including _control).
Correct approach should be:
// obtain configured instance of Latte Template:
$template = clone $presenter->getTemplate();
// set custom source file (without this, it would use presenter's current action's template file)
$template->setFile(__DIR__ . '/../../templates/yourEmailMessageTemplateFile.latte');
// add your custom parameters at once:
$template->setParameters($this->params);
// or one by one:
$template->foo = 'foo';
$template->bar = 'bar';
// create the email message object:
$message = new Nette\Mail\Message;
// optionally add message object to template to allow its manipulation from within the template file:
$template->mail = $message;
// prepare the email message:
$message->setFrom($fromEmail/* , $fromName*/)
->addTo($targetEmail/* , $targetName*/)
->setHtmlBody((string) $template)
->setSubject($subject); // optional, will be set by setHtmlBody if <title>Subject</title> is found in the template file
// send the message:
$mailer->send($message);
Last edited by duke (2015-02-18 01:42)