0
我想用小模板系統發送多封郵件。我嘗試自己,但並不是一切順利。我有這個模板PHPMailer - 用模板系統發送多封郵件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>new email template</title>
</head>
<body>
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
<div align="center">
Hi,
<p> I would like to send at your email {email}</p>
<p> a little hash sum {hash}</p>
</div>
</div>
</body>
</html>
而且我PHPMailer的片段(最多隻能配置我的郵件帳戶)
$mail->Subject = "Mail sending template";
$recipients = array(
'[email protected]' => 'gfsggsfg5t653rwtwrwtwrt',
'[email protected]' => '6536536536356363636536356',
);
foreach($recipients as $email => $hash) {
$mail->addAddress($email);
$vars = array('{email}','{hash}');
$values = array($email,$hash);
$body = str_replace($vars,$values,$body);
$mail->msgHTML($body);
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
if (!$mail->send()) {
echo "Mailer Error (" . str_replace("@", "@", $email) . ') ' . $mail->ErrorInfo . '<br />';
break;
} else {
echo "Send ok for: :" .$email . ' (' . str_replace("@", "@", $email) . ')<br />';
}
$mail->clearAddresses();
$mail->clearAttachments();
}
當我嘗試發送這些電子郵件將其發送OK。我可以收到電子郵件,但都有這些相同的數據:從收件人的第一個「行」([email protected])。從[email protected]我可以收到一封電子郵件,但可以通過[email protected]發送{email}和{hash}。
怎麼了?
感謝您的幫助:)
是的,我做的正是這就是你輸入:)我必須補充的file_get_contents功能分爲循環:) – Arlid
你並不需要。正如我發佈的代碼所做的那樣,在循環之前閱讀模板並重新使用它。 – Synchro