php tutorial mass mailing (phpmailer send qq mail) * @ author ray * @ since 2009-08-07
smtp mail account must be more, otherwise it will be qq server as spam. Have proper sleep
smtp.dat file format is smtp.163.com | sss@163.com | password smtp.sina.com | www@sina.com | password www.jzread.com The program randomly pick a connection, send mail, if the send is unsuccessful, the mail address is stored in sleepmail.dat dormant for 30 minutes after sending (this is to connect smtp server to send unsuccessful changes). * /
define ('__ debug__', false); define ('__ ps tutorial w_file__', dirname (__ file__). '/smtp.dat'); define ('sleeping_email', dirname (__ file__). "/sleepmail.dat");// Hibernate email define ('sleeping_time', 1800); // How long to sleep, in seconds 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 (); // Recipient and mail title and mail content $ 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: $ subjectrn "; } if (empty ($ mailfile) || empty ($ to) || empty ($ subject)) { $ errorno = 1; $ errormsg = "parameter is incomplete"; } // Load list of unavailable emails if (! $ errorno) { if (file_exists (sleeping_email)) { $ sleepmails = file (sleeping_email); if (! empty ($ sleepmails)) {
foreach ($ sleepmails as $ sleepmail) { // resolve if (false! == strpos ($ sleepmail, '|')) { $ tmp = explode ('|', $ sleepmail); if (isset ($ tmp [0]) && isset ($ tmp [1])) { $ mail = trim ($ tmp [0]); $ time = trim ($ tmp [1]);
//it's usable or not if (($ currtime - $ time) <sleeping_time) { $ unusemails [] = $ mail; } } } } } } } if (! $ errorno) { Random loading smtp server and smtp user name and password $ info = file (__ psw_file__); $ len = count ($ info);
do { $ rnd = mt_rand (0, $ len - 1); $ line = isset ($ info [$ rnd])? $ info [$ rnd]: "";
$ smtpserver = trim ($ tmp [0]); $ frommail = trim ($ tmp [1]); $ psw = trim ($ tmp [2]); $ smtpusername = substr ($ frommail, 0, strrpos ($ frommail, '@')); } } } while (in_array ($ frommail, $ unusemails)); // If it is not available in the list,
if (! isset ($ smtpserver) ||! isset ($ frommail) ||! isset ($ psw)) { $ errorno = 2; $ errormsg = "did not find the sender qq mail and password"; } } if (! $ errorno && __debug__) { echo "smtp: $ smtpserver from: $ frommail psw: $ psw user: $ smtpusernamern"; } if (! $ errorno) { / / Phpmailer smtp server to send letters 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.jzread.com used to show the specific smtp error
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.