Jump to content

Insert text into body of email using phpmailer


njdubois

Recommended Posts

I have this code :

$mail->addAddress("[email protected]", "bob");
$mail->Subject  = "subject(PHPMailer test using MAIL)";
$body = <<<'EOT'
BODY OF EMAIL
EOT;

I have a variable

 

$email_message

 

How do I replace BODY OF EMAIL

 

with the contents of that variable?

 

I've tried

$mail->addAddress("[email protected]", "bob");
$mail->Subject  = "subject(PHPMailer test using MAIL)";
$body = <<<'EOT'
$email_message
EOT;

// AND

$mail->addAddress("[email protected]", "bob");
$mail->Subject  = "subject(PHPMailer test using MAIL)";
$body = <<<'EOT'$email_messageEOT;

//AND

$mail->addAddress("[email protected]", "bob");
$mail->Subject  = "subject(PHPMailer test using MAIL)";
$body = <<<'EOT'
".$email_message."
EOT;

What one earth am I doing wrong?

 

Many many Thanks!!

 

Nick

Now Doc

 

 

Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping. It shares some features in common with the SGML <![CDATA[ ]]> construct, in that it declares a block of text which is not for parsing.

 

A nowdoc is identified with the same <<< sequence used for heredocs, but the identifier which follows is enclosed in single quotes, e.g. <<<'EOT'. All the rules for heredoc identifiers also apply to nowdoc identifiers, especially those regarding the appearance of the closing identifier.

(emphasis added)

 

Try it without the single quotes (Here Doc)

$body = <<<EOT
$email_message
EOT;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.