希望有人可以帮助我。 我想用php发送新闻通讯,并将数据库中的一些值放入其中。我可以构建HTML邮件,但我不能将php变量放入其中。这是我的代码:
<?php
$subject = "Newsletter";
if (isset($_POST['submit'])) {
$to = "to@mail.com";
$name = "Firstname Lastname";
$contactEmail = "contact@mail.com";
$message = "message";
$htmlContent = '
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<p>test</p>
<p>$name</p>
<p>$contactEmail</p>
<p>$message</p>
</body>
</html>
';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: from@mail.com' . "\r\n";
if(mail ($to, $subject, $htmlContent, $headers))
{
$successMessage = "Newsletter is sent.";
} else {
$messageError ="There is an error with your newsletter.";
}
}
?>