开发者

Dynamic Content into mail() $message

I'm just trying to put together a simple HTML email confirming an order to my database.

My $message looks a little like:

$message = "
<html>
<head>
<title>Whatever</title>
</head>
<body>

etc etc
</body>
</html>
";

What i want to do within the $message HTML is make a call to my database which will return rows something like:

$emailinfo=mysql_fetch_assoc($result) or die(mysql_error()); 

To which i can then use in my $message along the lines of:

<p><?php echo $emailinfo['customername'];?></p>

There's nothing wrong with my query or my tables e开发者_运维百科tc, the problem i'm having and need help with is getting the results from mysql_fetch_assoc into my $message html.

Can anyone help?

Thanks Dan


You can do something like this:

Example:

$message = <<<END
<html>
  <head>
    <title>Whatever</title>
  </head>
  <body>
    <p>{$emailinfo['customername']}</p>
  </body>
</html>
END;

There are several other ways to achieve this. For more information, see http://php.net/manual/en/language.types.string.php.

Loop example:

<?php

while ( $emailinfo = mysql_fetch_assoc($result) )
{
  // The "END;" must be at the start of the line (e.g. no white spaces before it).
  $message = <<<END
    <html>
      <head>
        <title>Whatever</title>
      </head>
      <body>
        <p>{$emailinfo['customername']}</p>
      </body>
    </html>
END;

  echo $message;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜