2011-09-27 58 views
0

我只是试图把一个简单的HTML电子邮件确认订单到我的数据库。

我的$消息看起来有点像:

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

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

我想在$消息HTML中做的就是到我的数据库的调用将返回行类似:

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

然后,我可以在我的$消息中沿着以下几行使用:

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

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

任何人都可以帮忙吗?

感谢 丹

+0

...你的意思是像'$消息= '你好' $ emailinfo [ '客户名称'];'。 '!'? – JJJ

回答

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; 
} 
+0

嗯,这看起来已经诀窍弗朗索瓦,非常感谢你,我一直在撕掉我的头发! :) – Dan

+0

我很高兴我能帮上忙。 –

+0

我还想在$ message Francios中通过一个while循环来运行,你可以帮助我们了解$ message中的语法如何?通常我会使用do {....}($ emailinfo = mysql_fetch_assoc($ result));但我不知道如何处理它,因此它的公认为php – Dan