phpmailer 群发代码
时间:2008-08-12 来源:yueming
?php
/**
* mailer
* 用来发送email,what the client what is so complex!
*
* related table:lr_mailsubscriber
*/
class mailer extends Controller {
function mailer(){
parent::Controller();
//$this->load->scaffolding("lr_users") ;
}
function index(){
//$this->load->view('welcome_message');
header("Location:/index.php");
}
public function doGroupSending($subject , $content){
if (empty($subject) || empty($content)){
echo "群发email的主题或者内容为空";
exit(0) ;
}
require_once("./WEB-INF/3partylibs/phpmailer/class.phpmailer.php") ;
$mail = new PHPMailer();
$mail->From = "[email protected]";
$success = true ;
/*loop address*/
$model = &AdminModelFactory::Factory("MailsubscriberModel") ;
$subscribers = $model->getAll() ;
foreach ($subscribers as $v){
$mail->ClearAddresses() ;
$mail->AddAddress($v['email']);
$mail->Subject = $subject;
$mail->Body = $content;
$mail->IsHTML(true);
if (!$mail->Send()){
$success = false ;
$error .= $v['email'] ;
}
}
/*~end loop address*/
if ($success){
echo "群发email给所有用户成功" ;
} else {
echo "群发失败
" ;
echo "一下用户没有成功发送:$error" ;
}
}
}
?>
相关阅读 更多 +