PHP - 不能在类方法中使用 Heredoc?

标签 php heredoc

我正在为 Controller 方法编写代码,我需要用它来发送电子邮件。我正在尝试使用 heredoc 语法来填写电子邮件正文,但是,似乎无法识别结束标记。

$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();  

开头的一切 <<< EOF down(直到文件末尾)显示为好像在引号中。

谁能看出为什么这不起作用?

感谢任何建议。

谢谢。

最佳答案

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

关于PHP - 不能在类方法中使用 Heredoc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2607849/

相关文章:

php - 如何从谷歌日历获取事件详情

php 没有从数据库中获取用户信息

javascript - 在 JavaScript 中创建多行字符串

linux - ssh 返回拒绝访问后调用 mysql 的 Bash 脚本

bash - 如何在 bash heredocs 中抑制变量替换

php - 习语查询数

php 分页 - 如何限制显示的页面数

PHP/MySQL 数组/numrows 交叉表

javascript - 将 PHP Heredoc 与 Javascript 模板文字相结合

带循环的 ruby​​ here-doc