我有这个脚本,它根据从csv文件收到的数据创建一个表 我想将这些数据发送到电子邮件地址,所以我尝试了PHPMailer。
到目前为止运气不错。我收到了basterd邮件,但是我发送到html正文的一些内容是在发送时创建的。无法弄清楚如何解决这个问题。
这是基本的PHPMailer
require("PHPmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.server.com";
$mail->SMTPAuth = true;
$mail->Username = "email@server.com";
$mail->Password = "password";
$mail->Port = "465";
$mail->SMTPSecure = "ssl";
$mail->From = "email@domain.nl";
$mail->FromName = "My Name";
$mail->AddAddress("email@somedomain.nl");
$mail->IsHTML(true);
$mail->Subject = "Subjectrule";
$mail->Body = "HERE I NEED TO PUT MY CODE</b>";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
这是正在生成的代码,这个代码的输出应该放在电子邮件的正文中,但对于我的生活,我不知道如何.... 这个想法是,如果一个人填写了一个电子邮件地址,他/她的所有数据都会被生成并放入电子邮件正文中
foreach ($saved as $final){
$bedrijf = $final['bedrijf'];
$factuurnummer= $final['factuurnummer'];
$gefactureerd = $final['gefactureerd'];
$email = $final['email'];
if ($bedrijf == $last_company) {
echo '
<font face="verdana" color="#868686" style="font-size: 12px;">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20" rowspan="4"></td>
</tr>
<tr height="30">
<td width="340" style="border-bottom: 1px solid #ebebeb;">
<font style="font-size: 12px;">'.$factuurnummer.'</font>
</td>
<td width="140" align="right" style="border-bottom: 1px solid #ebebeb">
<font style="font-size: 12px;">'.number_format($gefactureerd, 0, ',', '.').'</font>
</td>
</tr>
</table>
</font>';
} else {
$b = 100;
echo '
<font face="verdana" color="#808183" style="font-size: 12px;">
<table width="520" border="0" cellspacing="0" cellpadding="0">
<tr height="124">
<td width="180" valign="top">
<img src="../images/email/logo.jpg" width="180" height="124">
</td>
<td width="340" valign="top">
<table width="340" border="0" cellspacing="0" cellpadding="0">
<tr height="56">
<td width="340" colspan="2" valign="top">
<img src="../images/email/border-top.jpg" width="340" height="56">
</td>
</tr>
<tr height="38">
<td width="284" align="right"><font style="font-size: 20px;">€ '.number_format($arr_sum[$bedrijf] / $b, 2, ',', '.').'</font></td>
<td width="56" valign="top">
<img src="../images/email/border-right.jpg" width="56" height="38">
</td>
</tr>
<tr height="30">
<td width="340" colspan="2" valign="top">
<img src="../images/email/border-right-large.jpg" width="340" height="30">
</td>
</tr>
</table>
</td>
</tr>
<tr height="228">
<td width="520" colspan="2" valign="top">
<img src="../images/email/squirrel.jpg" width="520" height="228">
</td>
</tr>
<tr height="50">
<td colspan="2"> </td>
</tr>
</table>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr height="40">
<td width="20" rowspan="3"></td>
<td width="480" colspan="2" style="border-bottom: 1px solid #ebebeb"><font style="font-size: 20px;"><strong>'.$bedrijf.'</strong></font></td>
</tr>
<tr height="30">
<td width="340" style="border-bottom: 1px solid #ebebeb">
<font style="font-size: 12px;"><strong>factuurnummer</strong></font>
</td>
<td width="140" colspan="2" align="right" style="border-bottom: 1px solid #ebebeb">
<font style="font-size: 12px;"><strong>Bedrag in EUR</strong></font>
</td>
</tr>
<tr height="30">
<td width="340" style="border-bottom: 1px solid #ebebeb">
<font style="font-size: 12px;">'.$factuurnummer.'</font>
</td>
<td width="140" align="right" style="border-bottom: 1px solid #ebebeb">
<font style="font-size: 12px;">'.number_format($gefactureerd, 0, ',', '.').'</font>
</td>
</tr>
</table>
</font>';
$last_company = $bedrijf;
$sum=0;
}
}
}else{
echo 'U heeft geen emailadres ingevult wat bij ons bekent is.';
}
它发送,我收到。问题是在代码的末尾有variables
正在更新。问题是,如果我把它放在html体内,变量没有被更新,我错过了一些值......