Jump to content

Recommended Posts

I am trying to echo out product names onto php mail. I have it in the $message variable, code is below (have cut out a lot of other stuff in there, HTML code is all working fine)

 

$message = '

 

'for($z=0;$z<$h;$z++) {
            
            echo "<tr>";
                echo '<td colspan="18">'.$_SESSION['transferproducts'.$z.''].'</td>';
                echo '<td colspan="2">'.$_SESSION['transferprices'.$z.''].'</td>';
            echo "</tr>";
            
            }'

 

';

 

I'm getting an error on the line where the "for" starts. How can I get it to work correctly?

Link to comment
https://forums.phpfreaks.com/topic/296704-php-code-in-php-mail/
Share on other sites

You want to use the concatenation assignment operator in the for loop not echo.

$message = '';

// generate html
for($z=0;$z<$h;$z++)
{
    $message .= "<tr>";
    $message .= '<td colspan="18">'.$_SESSION['transferproducts'.$z.''].'</td>';
    $message .= '<td colspan="2">'.$_SESSION['transferprices'.$z.''].'</td>';
    $message .= "</tr>";
} 

// output generated html
echo $message;
Edited by Ch0cu3r

But I've got some stuff required in the message as well that shouldn't be repeated by the for loop. For example a confirmation of order message and customer ID.

 

Would I just put $message .= ..... before the for loop as well as having the for loop like above?

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.