我正在尝试从DB获取变量的php邮件服务,然后将值插入HTML以测试我正在尝试这样的事情:
<?php
include("db/dbvalue.php");
include("emailfun/email.php");
$response = array();
$emailaddress = "probh@pro.com";
$dt = new DateTime();
echo $dt->format('m-d');
$m = $dt->format('m');
$d = $dt->format('d');
$result = mysql_query("SELECT * FROM nameValue WHERE type = 'Boys' AND month = '$m' AND date = '$d'");
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
$name = $row["name"];
$to= $emailaddress;
$subject ="Congratulations";
$message="
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>Name goes here: <?php echo $name; ?> </p>
</body>
</html>
";
$from = "mailsender@pro.com";
$fromname = "Mail Sender";
send_html_mail($to, $subject, $message, $from, $fromname);
}
}
else
{
echo("NOTHING TODAY");
}
?>
我收到邮件但只是&#34;姓名在这里:&#34;
我根本无法在html中插入变量。
有人可以帮我解决这个问题吗?
谢谢!
答案 0 :(得分:2)
更改
<p>Name goes here: <?php echo $name; ?> </p>
到
<p>Name goes here: $name </p>
它会起作用。
通过插入<?php
... ?>
切换到php模式没有任何意义,因为......
答案 1 :(得分:1)
将姓名传递到电子邮件中的行应为:
<p>Name goes here: " . $name . "</p>
完整的$message
内容将是:
$message="
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>Name goes here: " . $name . "</p>
</body>
</html>
";
答案 2 :(得分:1)
您可以插入或连接。 了解有关此SO问题的更多信息: PHP variable interpolation vs concatenation