email - PEAR Mail, Mail_Mime and headers() overwrite -
i'm working on reminder php script called via cronjob once day in order inform customers smth.
therefore i'm using pear mail function, combined mail_mime. firstly script searches users in mysql database. if $num_rows > 0
, it's creating new mail
object , new mail_mime
object (the code encluded in posts starts @ point). problem appears in while-loop.
to exact: problem is
$mime->headers($headers, true);
as doc. states, second argument should overwrite old headers. outgoing mails sent header ($header['to']
) first user.
i'm going crazy thing... suggestions?
(note: it's sending correct headers when calling $mime = new mail_mime()
each user - should work calling once , overwriting old headers)
code:
// sql query , 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 <service@xy.at>'; $headers['subject'] = '=?utf-8?b?'.base64_encode('subject').'?='; $headers['reply-to'] = 'xy <service@xy.at>'; 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'].'>'; // testing purpose i'm sending mails webmaster@xy.at $to = '=?utf-8?b?'.base64_encode($row['firstname'].' '.$row['lastname']).'?= <webmaster@xy.at>'; $headers['to'] = $to; // sets in headers new $body = $mime->get(array('head_charset' => 'utf-8', 'text_charset' => 'utf-8', 'html_charset' => 'utf-8')); $hdrs = $mime->headers($headers, true); // although second parameters says true, second, thrid, ... mail still includes to-header form first user $sent = $mail->send($to, $hdrs, $body); if (pear::iserror($sent)) { errlog('error while sending user_id: '.$row['id']); // personal error function } else { // write log file } }
there no reason keep old object , not creating new one. use oop , create new objects - not know how work internally.
Comments
Post a Comment