Jump to content

Insert text into body of email using phpmailer


Go to solution Solved by Barand,

Recommended Posts

I have this code :

$mail->addAddress("bob@gmail.com", "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("bob@gmail.com", "bob");
$mail->Subject  = "subject(PHPMailer test using MAIL)";
$body = <<<'EOT'
$email_message
EOT;

// AND

$mail->addAddress("bob@gmail.com", "bob");
$mail->Subject  = "subject(PHPMailer test using MAIL)";
$body = <<<'EOT'$email_messageEOT;

//AND

$mail->addAddress("bob@gmail.com", "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;
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.