简体   繁体   中英

PHP - Cannot use Heredoc within a class method?

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 = '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 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.

检查“ EOF”后的分号后是否没有空格。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM