1

I am not so into PHP and I have some problem with this code snippet that should represent an e-mail that I will send:

$token = md5(uniqid($data['email'], true));

DB::insert('insert into pm_user(firstname, lastname, email, login, pass, type, token) values(?, ?, ?, ?, ?, ?, ?)',
            [$data['name'], $data['surname'], $data['login'], $data['email'], md5($data['pass']), 'hotel', $token]);


$registrationMail = [
     'title' => 'Registrazione albergatore su portale BeTrivius',
     'content' => "<p>Hi,<br>You created a new account.<br>
            Click on the link bellow to validate your account:<br>
            <a href=\".getUrl().\"?token=\".$token.\"&email=\".$data['email'].\">Validate my new account</a></p>\";
]

The problem is that PhpStorm sign me error on the $data['email'] variable into the content section of the message. Passing the mouse on this variable it says:

Cannot use [] for reading

So what is the problem? How can I correctly concatenate the content of $data['email'] variable in my e-mail message content?

  • `...email=\"".$data['email']."\">...` – Jeff Mar 01 '17 at 13:04
  • how do you initialize $data variable? did you try var_dump on it? – boroboris Mar 01 '17 at 13:05
  • 1
    or `...email=\"{$data['email']}\">...` – Jeff Mar 01 '17 at 13:05
  • similar problem here `...href=\".getUrl().\"?tok...` -> should be `..href=\"".getUrl()."?tok..` – Jeff Mar 01 '17 at 13:07
  • aside to Jeff answer, there should not be a `"` at the end of the expression inside an array declaration, the string is not ended – Kaddath Mar 01 '17 at 13:07
  • 1
    read about string concatanation, quotes, and escaping quotes. – Jeff Mar 01 '17 at 13:08
  • PhpStorm is correct here -- the string is **very** messy ad hard to read + it is simply invalid (you have lost `"` somewhere in between). Try rewriting it from scratch. Preferably (for easier editing) using HEREDOC syntax – LazyOne Mar 01 '17 at 13:08
  • @LazyOne HEREDOC would make this worse, not better. Switch to single quotes `'` for your string delimiters and stop escaping the double quotes `"`. There's too much escaping going on – Machavity Mar 01 '17 at 13:10
  • @Machavity I see now that he uses `getUrl()` which seems to be ordinary function. With that in mind HEREDOC will indeed not help here. – LazyOne Mar 01 '17 at 13:13

0 Answers0