如有问题,请联系 1184139881@qq.com
email.php
<?php
header("Content-type:text/html;charset=utf-8");
require 'phpmail/PHPMailerAutoload.php';
$dsn = 'mysql:host=127.0.0.1;dbname=library;port=3306;charset=utf8';
$pdo = new \PDO($dsn,'root','root');
$sql = "select * from email where is_no=0 and nub<=3";
$data = $pdo->query($sql)->fetchAll(\PDO::FETCH_ASSOC);
// var_dump($data);exit;
$mail = new PHPMailer();
$email = new myemail();
// 719305759@qq.com
// 1290528913@qq.com
foreach ($data as $k => $v) {
$url = $v["email_url"];
$aa = $email->email($mail,$url);
echo $aa."<br>";
}
class myemail{
public $host='smtp.qq.com';
public $username='1184139881@qq.com';
public $smtpsecure= 'xxx';
public function email($mail,$youname){
//var_dump($mail );exit;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $this->host; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $this->username; // SMTP username
$mail->Password = 'znvkwgmopzndcbaa'; // SMTP 授权码
$mail->SMTPSecure = $this->smtpsecure; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom($this->username, 'Mailer');
$mail->addAddress($youname, 'Joe User'); // Add a recipient
// $mail->addAddress('1142165466@qq.com'); // Name is optional
$mail->addAttachment('http://easyread.ph.126.net/f4GyETZyCBST24wxevNgrw==/7916587074082229398.jpg'); // Add attachments
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = '渲染';
$mail->Body = ' 大家好<img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503070900379&di=0c0648c40e2941f161e26fc04a29875d&imgtype=0&src=http%3A%2F%2Fpic5.qiyipic.com%2Fcommon%2F20130524%2F7dc5679567cd4243a0a41e5bf626ad77.jpg%3Fsrc%3Dfocustat_4_20130527_7" style="width:100px;height:100px;"><a href="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503070900379&di=0c0648c40e2941f161e26fc04a29875d&imgtype=0&src=http%3A%2F%2Fpic5.qiyipic.com%2Fcommon%2F20130524%2F7dc5679567cd4243a0a41e5bf626ad77.jpg%3Fsrc%3Dfocustat_4_20130527_7">查看这个图片</a>';
// $mail->AltBody = '哈哈哈哈哈^=^<a href="192.168.1.245">确认激活<a>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
$mail->clearAddresses();
$mail->clearAttachments();//如果有附件,附件也clear一下
echo 1 ;//'消息已sentnull';
}
}
}
?>
此外,还需下载三个文件,class.phpmailer.php, class.phpmaileroauth.php, class.smtp.php