PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

[FIXED] cakePHP 3 link inside email view

 January 17, 2022     cakephp, cakephp-3.0, email     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing