What is this <<< EMAIL_MESSAGE

I obtained a piece of code to send eMail with attachments and part of the code I do not understand!

How does the <<< EMAIL_MESSAGE work? Is it not straight PHP?

$message = <<<EMAIL_MESSAGE
–PHP-mixed-$random_hash
Content-Type: text/html; charset=“iso-8859-1”; boundary="PHP-alt-$random_hash

Hello World!

This is something with HTML formatting.

--PHP-mixed-$random_hash Content-Type: application/pdf; name="$file1" Content-Transfer-Encoding: base64 Content-Disposition: attachment

$attachment1
–PHP-mixed-$random_hash
Content-Type: image/jpg; name="$file2"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

$attachment2
–PHP-mixed-$random_hash–
EMAIL_MESSAGE;

What do you mean? It is a string assignment called a, HEREDOC.

I have not ever seen this before.

I looked it up now that I know what it is and found my problem "The closing identifier must begin in the first column of the line. "

I coped the code into my script and it was indented - it kept telling me that it was finding an error at end of the script. This explains it.

Thank you//

That’s one of the reasons I never like using HEREDOC.

The syntax takes getting use to, but I prefer to use it for long strings. It is actually how I prefer to handle long SQL statements as well.

Because the end needs to be at the start of the line?

The end needs to start a beginning of a line otherwise it does not work!

I learned something today.//

It’s a delimiter. You are telling the parser what the end of the string will be. You do the same thing in stored procedures for database programming.

Sponsor our Newsletter | Privacy Policy | Terms of Service