Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Cannot use Heredoc within a class method?

Tags:

php

heredoc

I'm writing the code for a controller method and I need to use it to send an email. I'm trying to use heredoc syntax to fill in the email body, however, the closing tag doesn't seem to be recognized.

$this->email = new Email(); 
$this->email->from = 'Automated Email';
$this->email->to = '[email protected]';
$this->email->subject = 'A new user has registered';
$this->email->body = <<<EOF

Hello, a new user has registered.

EOF;

$this->email->send();  

Everything from the opening <<< EOF down (till the end of the file) is displayed as if it was in quotes.

Can anyone see why this is not working?

Any advice appreciated.

Thanks.

like image 288
Dan Avatar asked Feb 28 '23 05:02

Dan


1 Answers

Check that you don't have any whitepace after the semicolon after "EOF".

like image 161
Matěj G. Avatar answered Mar 13 '23 06:03

Matěj G.