0
我目前正在研究一个提醒PHP脚本,它将通过Cronjob每天调用一次,以告知客户有关smth。PEAR Mail,Mail_Mime和标题()覆盖
因此,我使用了PEAR Mail功能,并结合Mail_Mime。首先,脚本在mysql数据库中搜索用户。如果$num_rows > 0
,它正在创建一个新的Mail
对象和一个新的Mail_mime
对象(此帖中包含的代码从此处开始)。现在问题出现在while循环中。
确切的说:问题是
$mime->headers($headers, true);
由于文档。状态,第二个参数应该覆盖旧的标题。但是,所有发出的邮件都会与第一位用户的标头($header['To']
)一起发送。
我真的很为这件事疯狂......有什么建议吗?
(注:但是它为每个用户通话$mime = new Mail_mime()
当的发送正确的头 - 但它应该与调用它只有一次,然后覆盖旧的接口兼容)
代码:
// sql query and if num_rows > 0 ....
require_once('/usr/local/lib/php/Mail.php');
require_once('/usr/local/lib/php/Mail/mime.php');
ob_start();
require_once($inclPath.'/email/head.php');
$head = ob_get_clean();
ob_start();
require_once($inclPath.'/email/foot.php');
$foot = ob_get_clean();
$XY['mail']['params']['driver'] = 'smtp';
$XY['mail']['params']['host'] = 'smtp.XY.at';
$XY['mail']['params']['port'] = 25;
$mail =& Mail::factory('smtp', $XY['mail']['params']);
$headers = array();
$headers['From'] = 'XY <[email protected]>';
$headers['Subject'] = '=?UTF-8?B?'.base64_encode('Subject').'?=';
$headers['Reply-To'] = 'XY <[email protected]>';
ob_start();
require_once($inclPath.'/email/templates/files.mail.require-review.php');
$template = ob_get_clean();
$crfl = "\n";
$mime = new Mail_mime($crfl);
while($row = $r->fetch_assoc()){
$html = $head . $template . $foot;
$mime->setHTMLBody($html);
#$to = '=?UTF-8?B?'.base64_encode($row['firstname'].' '.$row['lastname']).'?= <'.$row['email'].'>'; // for testing purpose i'm sending all mails to [email protected]
$to = '=?UTF-8?B?'.base64_encode($row['firstname'].' '.$row['lastname']).'?= <[email protected]>';
$headers['To'] = $to; // Sets to in headers to a new
$body = $mime->get(array('head_charset' => 'UTF-8', 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8'));
$hdrs = $mime->headers($headers, true); // although the second parameters says true, the second, thrid, ... mail still includes the To-header form the first user
$sent = $mail->send($to, $hdrs, $body);
if (PEAR::isError($sent)) {
errlog('error while sending to user_id: '.$row['id']); // personal error function
} else {
// Write log file
}
}
问题是服务器上的旧版本,由于一些非常奇怪的配置问题,忽略了$ overwrite参数。 – 2011-04-16 12:05:48