我正在尝试使用PHP Mailer发送动态电子邮件。我面临的问题是变量值没有进入电子邮件,事实上,从存储变量的p标签发送的电子邮件中没有任何内容。然而,电子邮件很好。不确定我错过了什么,请参阅下面的代码: -
<html>
<head>
<style>
.email-background {
background: #eee;
padding:10px;
}
.email-container {
max-width:800px;
background: #fff;
margin:0 auto;
padding:20px;
color: #b3d1ff;
}
.pre-header {
max-width: 800px;
background: #66a3ff none repeat scroll 0% 0%;
text-align: center;
margin: 0px auto;
padding: 20px;
font-size: 20px;
font-weight: 800;
font-family: montserrat;
color: #fff;
}
img {
max-width:100%;
}
hr {
display: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border: 2px solid #eee;
}
</style>
</head>
<body>
<div class="email-background">
<div class="pre-header">
Your Weekly.......
</div>
<div class="email-container">
<p>Dear %$firstname%,</p>
<h1>Test Email</h1>
<tr>
<td>
test1 test2
</td>
<td>
firstname
Lastname
<hr>
</td>
</tr>
<div class="email-footer">
</div>
</div>
</div>
</body>
</html>
$mail = new PHPMailer(true);
$mail->IsMail();
$mail->setFrom('test.com');
$mail->addAddress($row3["email"]); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'test email!!!';
$body= file_get_contents ('/Autoaction/phpmailer.html');
$body = str_replace('%$firstname%',$firstname,$body);
$body = preg_replace('/\\\\/','', $body);
$mail->msgHTML($body);
//$mail->Send();
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}