PHP - 无法在类方法中使用 Heredoc?
我正在编写控制器方法的代码,我需要使用它来发送电子邮件。我正在尝试使用heredoc语法来填写电子邮件正文,但是,结束标签似乎无法被识别。
$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();
一切都从开头 <<< EOF
向下(直到文件末尾)显示为就像在引号中一样。
谁能明白为什么这不起作用?
任何建议表示赞赏。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查“EOF”后的分号后是否有任何空格。
Check that you don't have any whitepace after the semicolon after "EOF".