php 邮件群发(phpmailer发送qq邮件)
*@author ray
*@since 2009-08-07
smtp邮件帐号一定要多,不然会被qq服务器当作垃圾邮件。
2.得适当的休眠
smtp.dat文件格式为
smtp.163.com|sss@163.com|密码
smtp.sina.com|www@sina.com|密码 www.111cn.net
程序随机抽取一个连接,发送邮件,如果发送不成功,将该邮件地址存入sleepmail.dat休眠30分后在发送(这个是为了连接smtp服务器多次后发送不成功而做的修改)。
*/
代码如下 | 复制代码 |
define('__debug__', false); define('__ps教程w_file__', dirname(__file__) . '/smtp.dat'); define('sleeping_email', dirname(__file__) . "/sleepmail.dat");//休眠的email define('sleeping_time', 1800);//休眠多长时间,以秒为单位 define('file_append', 1); if (!function_exists('file_put_contents')) { function file_put_contents($n, $d, $flag = false) { $mode = ($flag == file_append || strtoupper($flag) == 'file_append') ? 'a' : 'w'; $f = @fopen($n, $mode); if ($f === false) { return 0; } else { if (is_array($d)) $d = implode($d); $byteswritten = fwrite($f, $d); fclose($f); return $byteswritten; } } } $errorno = 0; $errormsg = ''; $currtime = time(); $unusemails = array(); //收件人和邮件标题和邮件内容 $to = isset($argv[1]) ? $argv[1] : "" ; $subject = isset($argv[2]) ? $argv[2] : ""; $mailfile = isset($argv[3]) ? $argv[3] : "" ; if (__debug__) { echo " file:$mailfile to:$to subject:$subject "; } if (empty($mailfile) || empty($to) || empty($subject)) { $errorno = 1; $errormsg = "参数不全"; } //加载不可用的email列表 if (!$errorno) { if (file_exists(sleeping_email)) { $sleepmails = file(sleeping_email); if (!empty($sleepmails)) { foreach($sleepmails as $sleepmail) { //解析 if (false !== strpos($sleepmail, '|')) { $tmp = explode('|', $sleepmail); if (isset($tmp[0]) && isset($tmp[1])) { $mail = trim($tmp[0]); $time = trim($tmp[1]); //是否可用 if ( ($currtime - $time )< sleeping_time) { $unusemails[] = $mail; } } } } } } } if (!$errorno) { //随机加载smtp服务器和smtp用户名和密码 $info = file(__psw_file__); $len = count($info); do { $rnd = mt_rand(0, $len - 1); $line = isset($info[$rnd]) ? $info[$rnd] : ""; if (false !== strpos($line, '|')) { $tmp = explode('|', $line); if (isset($tmp[0]) && isset($tmp[1]) && isset($tmp[2])) { $smtpserver = trim($tmp[0]); $frommail = trim($tmp[1]); $psw = trim($tmp[2]); $smtpusername = substr($frommail, 0, strrpos($frommail, '@')); } } }while (in_array($frommail, $unusemails));//如果在不可用的列表中,在次加载 if (!isset($smtpserver) || !isset($frommail) || !isset($psw)) { $errorno = 2; $errormsg = "没找到发件人qq信箱和密码"; } } if (!$errorno && __debug__) { echo "smtp:$smtpserver from:$frommail psw:$psw user:$smtpusername "; } if (!$errorno) { //通过phpmailer连接smtp服务器发信 require(dirname(__file__) . "/phpmailer/class.phpmailer.php"); require(dirname(__file__) . "/phpmailer/class.smtp.php"); $mail = new phpmailer(); $body = $mail->getfile($mailfile); $body = eregi_replace("[]",'',$body); //charset $mail->charset = "gb2312"; //$mail->smtpdebug = 2;//www.111cn.net用于显示具体的smtp错误 $mail->issmtp(); $mail->smtpauth = true; if ("smtp.qq.com" == trim($smtpserver)) { $mail->username = $frommail; } else { $mail->username = $smtpusername; } $mail->password = $psw; $mail->host = $smtpserver; $mail->from = $frommail; $mail->fromname = "晴天网络"; $mail->ishtml(true); $mail->addaddress($to); $mail->subject = $subject; $mail->body = $body; if (!$mail->send()) { // echo "message could not be sent. "; $errorno = 3; $errormsg = $mail->errorinfo; } else { echo " send to $to success use $frommail "; exit; } } if (3 == $errorno) { //记录信息,该信息地址休眠n分钟 $content = "$frommail|" . time() . " ";//email|当前时间戳 file_put_contents(sleeping_email, $content, file_append); } echo " error no($errorno) " . $errormsg . " "; exit; |
代码如下 | 复制代码 |
<html> <body> </body> |
-- php教程myadmin sql dump
-- version 2.11.6
-- http://www.phpmyadmin.net
--
-- host: localhost
-- generation time: jun 29, 2010 at 09:27 am
-- server version: 5.0.51
-- php version: 5.2.6
set sql_mode="no_auto_value_on_zero";
/*!40101 set @old_character_set_client=@@character_set_client */;
/*!40101 set @old_character_set_results=@@character_set_results */;
/*!40101 set @old_collation_connection=@@collation_connection */;
/*!40101 set names utf8 */;
--
-- database: `test`
--
-- --------------------------------------------------------
--
-- table structure for table `maillist`
--
create table if not exists `maillist` (
`id` int(11) not null auto_increment,
`title` text collate utf8_unicode_ci not null,
`content` mediumtext collate utf8_unicode_ci not null,
`senduser` varchar(50) collate utf8_unicode_ci not null,
`sendmail` varchar(200) collate utf8_unicode_ci not null,
`sendtime` int(11) not null,
`accept_email` varchar(200) collate utf8_unicode_ci not null,
`cc_email` varchar(200) collate utf8_unicode_ci not null,
`bcc_email` varchar(200) collate utf8_unicode_ci not null,
`msessage_id` varchar(200) collate utf8_unicode_ci not null,
`msgno` int(11) not null comment '邮件的序号,为0表示已经下载结束',
`is_download` tinyint(4) not null default '0',
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=1 ;
--
-- dumping data for table `maillist`
--
-- --------------------------------------------------------
--
-- table structure for table `mail_account`
--
create table if not exists `mail_account` (
`id` int(11) not null auto_increment,
`username` varchar(100) not null,
`password` varchar(50) not null,
`emailaddress` varchar(100) not null,
`mailserver` varchar(50) not null,
`servertype` varchar(10) not null,
`port` varchar(10) not null,
primary key (`id`)
) engine=myisam default charset=latin1 auto_increment=1 ;
--
-- dumping data for table `mail_account`
--
-- --------------------------------------------------------
--
-- table structure for table `mail_attach`
--
create table if not exists `mail_attach` (
`id` int(11) not null auto_increment,
`mail_id` int(11) not null,
`filename` varchar(200) collate utf8_unicode_ci not null,
`filename_tmp` varchar(200) collate utf8_unicode_ci not null,
`download_time` datetime not null,
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=1 ;
--
-- dumping data for table `mail_attach`
--
这是一款免费的php发送邮件代码-用mail哦,是基础php自身的上传函数
代码如下 | 复制代码 |
<html> |
php代码
代码如下 | 复制代码 |
<?php |
代码如下 | 复制代码 |
<?php <?php |
相关文章
- 本文给大家介绍的是nodejs实现使用阿里大鱼短信API发送消息的方法和代码,有需要的小伙伴可以参考下。...2016-01-20
- mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
- 这篇文章研究的主要内容就是使用PHP来发送电子邮件,总结为以下两种方法:一、使用PHP内置的mail()函数<?php $to = "test@163.com"; //收件人 $subject = "Test"; //主题 $message = "This is a test mail!"; //正文...2015-10-30
- 这篇文章主要介绍了c# 如何实现发送邮件的功能,文中示例代码非常详细,帮助大家更好的理解和学习,感兴趣的朋友可以了解下...2020-07-07
- 这篇文章研究的主要内容就是使用PHP来发送电子邮件,总结为以下两种方法:一、使用PHP内置的mail()函数<?php $to = "test@163.com"; //收件人 $subject = "Test"; //主题 $message = "This is a test mail!"; //正文...2015-10-30
- 这篇文章主要介绍了python实现企业微信定时发送文本消息的实例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-25
- 这篇文章主要介绍了c#使用netmail方式发送邮件的示例,大家参考使用吧...2020-06-25
- mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
- PHPMailer在SAE上无法发送邮件怎么回事呢,我们以前在php5.2.7版本中使用了PHPMailer是可以发,但移到sae中发现无法发邮件了,那么此问题如何解决 在SAE上直接用5.2.7...2016-11-25
- 本文我们整理了三个android后台发送邮件的方法及示例,第一个是不借助Intent在android后台发送Email,第二个是用在收集应用的异常信息,第三个是分享一个android后台发送邮...2016-09-20
- 这篇文章主要介绍了Perl中使用MIME::Lite发送邮件实例,本文介绍了使用sendmail方式发送、发送HTML格式邮件、smtp方式发送邮件等内容,需要的朋友可以参考下...2020-06-29
网上找到的两个PHP发送邮件的例子,很不错,贴出来给初学者参考吧(不知道是否有兄弟曾贴过),呵呵(2
Advanced Example Here we will show the full capabilities of the PHP mail function. PHP Code: <?php echo "<html><body>"; $recipient = "Kris Arndt <karn@nu...2016-11-25- 这篇文章主要介绍了Delphi7中群发Email邮件的方法,涉及邮件服务器软件的使用,电子邮件的判断与发送功能的实现,是非常实用的技巧,需要的朋友可以参考下...2020-06-30
node.js 基于 STMP 协议和 EWS 协议发送邮件
这篇文章主要介绍了node.js 基于 STMP 协议和 EWS 协议发送邮件的示例,帮助大家更好的理解和使用node.js,感兴趣的朋友可以了解下...2021-02-15- 学过asp的朋友可能知道jmail组件是使用在asp中一个常用的邮箱发送功能,在php中如果想调用jmail功能我们需要使用com组件来操作。 我们先来介绍格式 代码如...2016-11-25
- //原创:www.111cn.net 注明:转载说明来处www.111cn.net // 昨天听一网友说用php 里面的mail发邮件发不出去,我想一般都是发不了的,现在大多数据邮件提供商都不准那样了...2016-11-25
- 这篇文章主要介绍了C#编程实现发送邮件的方法,具备添加附件的功能,涉及C#文件传输及邮件发送的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 本文章来介绍人一下关于与我们不同的发送邮件的方法我们来利用php curl stmp来实现邮件的发送程序。 $ telnet 邮箱SMTP服务地址 25 Trying 邮箱服务IP地址......2016-11-25
- 这篇文章主要介绍了Python基于httpx模块实现发送请求,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-07-08
- <?php // 请求 PHPmailer类 文件 require_once("class.phpmailer.php"); //发送Email函数 function smtp_mail ( $sendto_email, $subject, $body, $extra_hd...2016-11-25