Thinkphp集成PHPmailer同时发送多人邮件

需要引用两个PHPmailer文件:PHPMailer.class.php      SMTP.class.php

<?php
namespace Admin\Controller;

/**
 * 其他控制器
 *
 * @author wangqiao
 */
class OtherController extends AdminController {
	
	public function email(){
		
		$this->display();
	}
	
	/*
	 * 邮件发送
	 */
	public function sends() {
		if(IS_POST){
			$tags = I('post.tags');
			$content = I('post.content');
			$title = I('post.title');
			$subscribe = M('MeetSubscribe');
			$list = $subscribe->where('type_id=%d',$tags)->field('email')->select();
			$lists = array_column($list,'email');
			$address = array_flip(array_flip($lists)); //获取订阅该类会议的邮箱,重复的邮箱不再重复取
			
			$this->sendMail($address, $title, $content);
		}
	}
	
	/*
	 * 邮件发送功能
	 */
	public function sendMail($address, $title, $content) {
		$mail=new \Org\Util\PHPMailer();
		$mail->CharSet = "utf-8";  //设置采用utf8中文编码
		$mail->IsSMTP();                    //设置采用SMTP方式发送邮件
		$mail->Host = "smtp.163.com";    //设置邮件服务器的地址  smtp.qq.com
		$mail->Port = 25;     //设置邮件服务器的端口,默认为25  gmail  443
		$mail->From = "[email protected]";  //设置发件人的邮箱地址
		$mail->FromName = "蟠桃会-专业的会议网站";                       //设置发件人的姓名
		$mail->SMTPAuth = true; // 设置SMTP是否需要密码验证,true表示需要
		//$mail->SMTPSecure = 'ssl'; // 使用安全协议
		$mail->Username = "[email protected]";
		$mail->Password = "ksxgjzlrhsrawyuq";
		$mail->Subject = $title;   //设置邮件的标题
		$mail->AltBody = "text/html";    // optional, comment out and  test  <a href="">abc</a>
		$mail->Body = $content;//发送的内容
		$mail->IsHTML(true);                                        //设置内容是否为html类型
		//$mail ->WordWrap = 50;                                 //设置每行的字符数
		$mail->AddReplyTo("[email protected]", "蟠桃会-专业的会议网站");     //设置回复的收件人的地址
		foreach ($address as $k => $v) {
			$mail->AddAddress($v);     //设置收件的地址
		}
		if (!$mail->Send()) {                    //发送邮件
			$this->error('fail:'.$mail->ErrorInfo);
		} else {
			$this->success('发送成功!');
		}
	}
}

PHPmailer 源文件下载:https://github.com/PHPMailer/PHPMailer/

已163邮箱为例:

$mail->Password = "ksxgjzlrhsrawyuq"; 此处密码是客户端授权密码,不是登录密码

已新浪邮箱为例:

$mail->Password = "ksxgjzlrhsrawyuq"; 此处的密码是登陆密码



你可能感兴趣的:(邮件,thinkphp,phpmailer)