$message = '
<html>
<head>
<title>Haftalık Rapor</title>
</head>
<body>
<table border="4" width="100%" cellpadding="2" cellspacing="3">
<tr>
<td bgcolor="#FF0000" align="center">Plaka no:</td>
<td bgcolor="#FF0000" align="center">Aracin Cinsi:</td>
<td bgcolor="#FF0000" align="center">Sikayet edilme sebebi:</td>
<td bgcolor="#FF0000" align="center">Tarih:</td>
</tr>
$con = mysql_connect("", "", "", "","");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("", $con);
$bilgi= mysql_query("SELECT plakano,aciklama,secim,tarih FROM bad ORDER BY tarih ASC");
while($sutun= mysql_fetch_array($bilgi))
{
echo "<tr>";
echo "<td align='center'> ".$sutun["plakano"]."</td>";
echo "<td align='center'> ".$sutun["secim"]."</td>";
echo "<td align='center'> ".$sutun["aciklama"]."</td>";
echo "<td align='center'> ".$sutun["tarih"]."</td>";
echo "</tr>";
}
';
这是一个邮件示例。但是我想从数据库中获取邮件的消息,任何人都可以帮助我这段代码有一个语法,但不知道如何解决它。
答案 0 :(得分:3)
$message = '
<html>
<head>
<title>Haftalık Rapor</title>
</head>
<body>
<table border="4" width="100%" cellpadding="2" cellspacing="3">
<tr>
<td bgcolor="#FF0000" align="center">Plaka no:</td>
<td bgcolor="#FF0000" align="center">Aracin Cinsi:</td>
<td bgcolor="#FF0000" align="center">Sikayet edilme sebebi:</td>
<td bgcolor="#FF0000" align="center">Tarih:</td>
</tr> ';
$con = mysql_connect("", "", "", "","");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("", $con);
$bilgi= mysql_query("SELECT plakano,aciklama,secim,tarih FROM bad ORDER BY tarih ASC");
while($sutun= mysql_fetch_array($bilgi))
{
$message .= "<tr>";
$message .= "<td align='center'> ".$sutun["plakano"]."</td>";
$message .= "<td align='center'> ".$sutun["secim"]."</td>";
$message .= "<td align='center'> ".$sutun["aciklama"]."</td>";
$message .= "<td align='center'> ".$sutun["tarih"]."</td>";
$message .= "</tr>";
}
答案 1 :(得分:1)
PHP代码必须在标签内。 而不是回显数据,您应该将它附加到消息。
$message = '<html>
<head>
<title>Haftalık Rapor</title>
</head>
<body>
<table border="4" width="100%" cellpadding="2" cellspacing="3">
<tr>
<td bgcolor="#FF0000" align="center">Plaka no:</td>
<td bgcolor="#FF0000" align="center">Aracin Cinsi:</td>
<td bgcolor="#FF0000" align="center">Sikayet edilme sebebi:</td>
<td bgcolor="#FF0000" align="center">Tarih:</td>
</tr>';
$con = mysql_connect("", "", "", "","");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("", $con);
$bilgi= mysql_query("SELECT plakano,aciklama,secim,tarih FROM bad ORDER BY tarih ASC");
while($sutun= mysql_fetch_array($bilgi))
{
$message .= "<tr>";
$message .= "<td align='center'> ".$sutun["plakano"]."</td>";
$message .= "<td align='center'> ".$sutun["secim"]."</td>";
$message .= "<td align='center'> ".$sutun["aciklama"]."</td>";
$message .= "<td align='center'> ".$sutun["tarih"]."</td>";
$message .= "</tr>";
}
答案 2 :(得分:1)
简单:
<?php
// do database query to get email template
$body = $row['name_of_column_containing_message_template_html'];
mail($to, $subject, $body, $headers);
答案 3 :(得分:1)
我认为你的数据库中已有消息,然后你需要的是选择消息,将其存储在变量中,然后调用$message
var。
请勿在$ message var:
中调用代码 $con = mysql_connect("", "", "", "","");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("", $con);
$bilgi= mysql_query("SELECT plakano,aciklama,secim,tarih FROM bad ORDER BY tarih ASC");
while($sutun= mysql_fetch_array($bilgi))
{
echo "<tr>";
echo "<td align='center'> ".$sutun["plakano"]."</td>";
echo "<td align='center'> ".$sutun["secim"]."</td>";
echo "<td align='center'> ".$sutun["aciklama"]."</td>";
echo "<td align='center'> ".$sutun["tarih"]."</td>";
echo "</tr>";
}
在$ message之前调用它并将值存储在其他变量中 - &gt; $plakano = $sutun["plakano"]
最终代码如下所示:
$con = mysql_connect("", "", "", "","");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("", $con);
$bilgi= mysql_query("SELECT plakano,aciklama,secim,tarih FROM bad ORDER BY tarih ASC");
while($sutun= mysql_fetch_array($bilgi))
{
$plakano = $sutun["plakano"];
$secim = $sutun["secim"];
$aciklama = $sutun["aciklama"];
$tarih = $sutun["tarih"];
$tr .= '
<tr>
<td> $plakano </td> <td> $secim </td> <td> $aciklama </td> <td> $tarih </td>
</tr>';
}
$message = '
<table border="4" width="100%" cellpadding="2" cellspacing="3">
<tr>
<td bgcolor="#FF0000" align="center">Plaka no:</td>
<td bgcolor="#FF0000" align="center">Aracin Cinsi:</td>
<td bgcolor="#FF0000" align="center">Sikayet edilme sebebi:</td>
<td bgcolor="#FF0000" align="center">Tarih:</td>
</tr>
' . $tr . '
</table>
';
// Send email (I suppose you getting the $to $subject and $headers from somewhere)
mail($to, $subject, $message, $headers);
答案 4 :(得分:0)
你在消息文本中有你的PHP代码。此外,您也有非转义'
标签。
您需要拆分该代码,以便在$ message赋值之外提取数据库。