Issue
I have an issue build a link inside an email view, it doesn't out put the URL i'm passing from the controller for some reason..
the URL string that i'm passing to the view is missing the http://domain
prefix
some action in usersController:
$email = new Email(['gmail','transport'=>'gmail']);
$email->template('recover', 'default')
->emailFormat('html')
->viewVars([
'username' => $user['username'],
'url' => '/users/resetpwd/u/'.$user['username'].'/t/'.$user['token']
])
->from(['mailer@domain.com' => 'My Site'])
->to('example@domain.com')
->subject('Password recovery')
->send()
recover.ctp:
<p>Welcome <b><?= $username; ?></b>,<br/>
you requested a password change.<br/>
To set a new password, please: <?php echo $this->Html->link('Click Here', $url, ['_full' => true,'escape' => true]); ?></p>
<?= $this->Html->image('banniere.gif', array('fullBase' => true));?><br/>
<p>This email was sent from <a href="http://cakephp.org">My Site</a></p>
Solution
If you want to ensure that the URL is always a "full" one, then the proper solution here is Router::url()
. That way you could even declare the URL in array format (which should normally be the preferred style anyways) without breaking things.
use Cake\Routing\Router;
// ...
<?= $this->Html->link('Click Here', Router::url($url, true), ['escape' => true]); ?>
Answered By - ndm
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.