【问题标题】:Dynamic Content into mail() $message动态内容到 mail() $message
【发布时间】:2011-09-28 02:58:14
【问题描述】:

我只是想整理一封简单的 HTML 电子邮件,确认我的数据库中的订单。

我的 $message 看起来有点像:

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

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

我想要在 $message HTML 中做的是调用我的数据库,它将返回如下行:

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

然后我可以在我的 $message 中使用以下内容:

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

我的查询或表格等没有问题,我遇到的需要帮助的问题是将结果从 mysql_fetch_assoc 获取到我的 $message html 中。

谁能帮忙?

谢谢 丹

【问题讨论】:

  • ...你的意思是像$message = 'Hello '.$emailinfo['customername'].'!';

标签: php


【解决方案1】:

你可以这样做:

示例:

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

还有其他几种方法可以实现这一点。如需更多信息,请参阅http://php.net/manual/en/language.types.string.php

循环示例:

<?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;
}

【讨论】:

  • 嗯,这看起来成功了弗朗索瓦,非常感谢你,我一直在扯头发! :)
  • 我还想在 $message Francios 中运行一个 while 循环,你能帮忙看看该语法如何适合 $message 吗?通常我会使用 do { .... } while ($emailinfo=mysql_fetch_assoc($result));但我不知道如何使用它,所以它被识别为 php
  • 你需要$message = ... 在你的循环中。
  • 似乎对弗朗索瓦不起作用,在 $message 之外它很好,但它似乎只与电子邮件结果中的第一行相呼应。
  • 似乎没有办法解决弗朗索瓦。我已经开始了一个新问题:stackoverflow.com/questions/7574316/…感谢您的帮助,非常感谢:)
猜你喜欢
  • 2014-11-26
  • 1970-01-01
  • 2012-08-05
  • 2011-07-28
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多