Reputation: 5954
I am trying out the php mail service getting the variable from DB and then insert the value to HTML to test I am was trying out something like this:
<?php
include("db/dbvalue.php");
include("emailfun/email.php");
$response = array();
$emailaddress = "[email protected]";
$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 = "[email protected]";
$fromname = "Mail Sender";
send_html_mail($to, $subject, $message, $from, $fromname);
}
}
else
{
echo("NOTHING TODAY");
}
?>
I am receiving the mail but just with "Name goes here:"
I am not able to get the variable inserted in the html at all.
Can somebody help me fix this?
Thanks!
Upvotes: 1
Views: 240
Reputation: 8617
You can either interpolate or concatenate. Find out more on this SO question: PHP variable interpolation vs concatenation
Upvotes: 1
Reputation: 4746
Change
<p>Name goes here: <?php echo $name; ?> </p>
to
<p>Name goes here: $name </p>
and it'll work.
Switching to php mode by inserting <?php
... ?>
makes no sense, because...
Upvotes: 2
Reputation: 27092
The line with passing name into email message should be:
<p>Name goes here: " . $name . "</p>
Full $message
content will be:
$message="
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>Name goes here: " . $name . "</p>
</body>
</html>
";
Upvotes: 1