PHP - Can't use Heredoc in a class method?

I am writing code for a controller method and I need to use it to send email. I am trying to use heredoc syntax to populate an email body, however the closing tag does not seem to be recognized.

$this->email = new Email(); 
$this->email->from = 'Automated Email';
$this->email->to = 'me@myemail.com';
$this->email->subject = 'A new user has registered';
$this->email->body = <<<EOF

Hello, a new user has registered.

EOF;

$this->email->send();  

Everything from opening <<< EOFdown (to the end of the file) is displayed as if it were in quotation marks.

Can anyone understand why this is not working?

Any advice is appreciated.

Thank.

+3
source share
1 answer

Make sure you don't have a space after the semicolon after "EOF".

+7
source

Source: https://habr.com/ru/post/1740458/


All Articles