0

Possible Duplicate:
Calling PHP functions within HEREDOC strings

I am using Swiftmailer PHP to create an order complete page. When the customer lands on this page, I use an include to a PHP file.

This page file has SwiftMailer EOM HTML that gets sent to the customer. However I have the HTML parts in chunks, so the header is via a function called header and order totals are the same too. I want to be able to include EOM functions inside the EOM. Is this possible?

Id  =       46088;

// MAIL FUNCTION
function mailToSend($Id){

// EOM CAN'T BE TABBED
$html = <<<EOM
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
getHeader($Id);
getOrderTotalBoxTable($Id);
</body>
</html>
EOM;


}

mailToSend(46088);
4
  • 1
    Could you not place the output of the function in to a variable and place that inside the heredoc? Commented Dec 17, 2012 at 15:43
  • 1
    What is EOM I have searched and I cannot find documentation about it Commented Dec 17, 2012 at 15:44
  • 1
    I can't tell you why, but this question is going to help you. Commented Dec 17, 2012 at 15:45
  • I’d suggest you look into templating. Commented Dec 17, 2012 at 15:53

2 Answers 2

1

Like @deceze said, you can't, but this will work (extend @xenon comment to an example):

function getHeader($Id = '')
{
    $text = '';
    $text.=' Your first line of text, store it in an variable <br>';
    $text.= 'Hello '.$Id.'<br>';
    $text.='Your last text to be returned<br>';
    return $text;
}

// MAIL FUNCTION
function mailToSend($Id){

    $getHeader = getHeader($Id);
    $getOrderTotalBoxTable = getOrderTotalBoxTable($Id);

    // EOM CAN'T BE TABBED
$html = <<<EOM
    <!DOCTYPE html>
    <html lang="en">
    <head>
    </head>
    <body>
    $getHeader;
    $getOrderTotalBoxTable;
    </body>
    </html>
EOM;

}

mailToSend(46088);
Sign up to request clarification or add additional context in comments.

7 Comments

Using this example, I have, example $getHeader as a function above, the code is like function getHeader($oid){ echo 'hello'; } so the email does send but it is blank at the function part, the page shows the hello do I need to put it in the global $html var??
I did not fully understood your question, but the function getHeader needs to return something, not print, something along these lines: "function getHeader($oid){ return 'hello '.$oid; }"
Can you show me an example, can I just do loads of returns??
You cannot do loads of returns.
Yes, so I made a $print variable inside the other function, and just did print="" and then print .="" etc and then then return $print is blank, but echo $print works... but echo does not include it inside the EOM
|
1

What you're talking about are Heredocs and they don't support function interpolation, only variable interpolation.

2 Comments

that will try to access a variable after a function is called?
Yes, corrected that statement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.