4

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.

2
  • What version of PHP are you using? Commented Apr 9, 2010 at 13:37
  • 1
    You had whitespace after EOF; - the ending identifier for heredoc strings must be completely isolated on it's own line, with no leading or trailing whitespace; see the big red warning here: php.net/manual/en/… Commented Apr 9, 2010 at 13:42

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

+1 nice catch. Highlighting the code reveals the bogus whitespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.