Session from Config

1

I have the following case: I want to send an email from cakephp, but since there is more than one user in the database (each containing a different email), I need to send each user's email and password to the / app file /Config/email.php, that is, simply get the session. There is already a method that captures the user's data, being $ this-> Session-> read ('UserList'), so you can pass the rest of the parameters: $ this-> Session-> read ('UserList' ) ['User'] ['email'] and $ this-> Session-> read ('UserLogic') ['User'] ['password'], however when trying to pass these session values to the email file .php, it gives an error saying that it is necessary to use this within a function.

email.php:

public $smtp = array(
            'host' => 'ssl://smtp.gmail.com',
            'port' => 465,
            'from' => array($_SESSION['UsuarioLogado']['User']['email'] => $_SESSION['UsuarioLogado']['User']['nome']),
            'username' => $_SESSION['UsuarioLogado']['User']['email'],
            'password' => $_SESSION['UsuarioLogado']['User']['senha'],
            'transport' => 'Smtp',
            'tls' => false // As of 2.3.0 you can also enable TLS SMTP
    );
    
asked by anonymous 06.04.2015 / 19:58

1 answer

1

In fact, you can not dynamically set the properties directly in the Email configuration file. You need to do this for Controller , for example.

By the config() method, you can either pass a string that represents one of the settings defined in these files, or an array with the SMTP configuration properties itself.

To do this, do something like this:

$sess = $this->Session->read('UsuarioLogado');

$Email = new CakeEmail();
$Email->config(array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'username' => $sess['User']['email'],
    'password' => $sess['User']['senha'],
));
    
07.04.2015 / 14:13