PHP實(shí)現(xiàn)郵件群發(fā)的源碼
更新時(shí)間:2013年06月18日 16:13:24 作者:
本篇文章是對(duì)用PHP實(shí)現(xiàn)郵件群發(fā)的代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
復(fù)制代碼 代碼如下:
<?php
// 請(qǐng)求 PHPmailer類 文件
require_once("class.phpmailer.php");
//發(fā)送Email函數(shù)
function smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name) {
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.163.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "jessiejl"; // SMTP username 注意:普通郵件認(rèn)證不需要加 @域名
$mail->Password = "1983106"; // SMTP password
$mail->From = ""; // 發(fā)件人郵箱
$mail->FromName = "WWW.NIUTW.COM"; // 發(fā)件人 ,比如 唯美搭配網(wǎng)
$mail->CharSet = "GB2312"; // 這里指定字符集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,$user_name); // 收件人郵箱和姓名
$mail->AddReplyTo("","Web之家");
//$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件1
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); //附件2
$mail->IsHTML(true); // send as HTML
$mail->Subject = $subject;
// 郵件內(nèi)容 可以直接發(fā)送html文件
$mail->Body = <<<EOT
<html>
<head>
<title>Treasurery Online 周刊</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
.STYLE1 {color: #009900}
.STYLE3 {color: #000000}
a:link {
color: #333333;
}
.STYLE4 {color: #666666}
body,td,th {
font-family: 宋體;
font-size: 12px;
}
.STYLE6 {color: #FFFFFF}
.STYLE9 {color: #DCB003}
-->
</style>
</head>
<body bgcolor="#FFFFFF" >
</body>
</html>
EOT;
$mail->AltBody ="text/html";
if($mail->Send())
{
info_write("ok.txt","$user_name 發(fā)送成功");
}
else {
info_write("falied.txt","$user_name 失敗,錯(cuò)誤信息$mail->ErrorInfo");
}
}
// 發(fā)送Email函數(shù)結(jié)束
// 寫入發(fā)送結(jié)果函數(shù),錯(cuò)誤日志記錄
function info_write($filename,$info_log)
{
$info.= $info_log;
$info.="\r\n";
$fp = fopen ($filename,a);
fwrite($fp,$info);
fclose($fp);
}
//定時(shí)跳轉(zhuǎn)頁(yè)面 函數(shù) 其中 1000是時(shí)間,1秒, 您可以自定義
function redirect($url)
{
echo "<script>
function redirect()
{
window.location.replace('$url');
}
window.setTimeout('redirect();', 15000);
</script>";
}
//讀取文本 郵件地址 您也可以讀 數(shù)據(jù)庫(kù)
$filename = "email.txt";
$fp = fopen($filename,"r");
$contents = fread($fp,filesize($filename));
$list_email=explode("\r\n",$contents);
$len=count($list_email);
fclose($fp);
// 參數(shù)說(shuō)明(發(fā)送到, 郵件主題, 郵件內(nèi)容, 附加信息, 用戶名)
$i = $_GET['action'];
$i++;
if ($i<$len)
{
$rs=explode("@",$list_email[$i]);
$user_name = $rs['0'];
echo "正在發(fā)送第{$i}封({$list_email[$i]})郵件......{$user_name}";
smtp_mail($list_email[$i], 'Treasurery Online 周刊第十二期', $body, 'http://www.yem120.com/', $user_name);
redirect("?action=$i");
}
else {
echo "郵件全部發(fā)送完畢";
exit;
}
?>
小思維:
上面的讀取文章email.txt,也可以直接是qq號(hào)碼,每行一個(gè)號(hào)碼,然后用fget()讀取每行qq號(hào)碼,最后在加上qq郵箱后綴 @qq.com即可
您可能感興趣的文章:
- PHP基于imap獲取郵件實(shí)例
- 用PHP讀取IMAP郵件
- redhat下apache+php+mysql+imap+ldap+jdk+tomcat的安裝
- PHPMailer使用教程(PHPMailer發(fā)送郵件實(shí)例分析)
- 功能齊全的PHP發(fā)送郵件類代碼附詳細(xì)說(shuō)明
- php郵件發(fā)送的兩種方式
- php中通過(guò)smtp發(fā)郵件的類,測(cè)試通過(guò)
- PHPMailer郵件類利用smtp.163.com發(fā)送郵件方法
- phpmailer在服務(wù)器上不能正常發(fā)送郵件的解決辦法
- php 發(fā)送帶附件郵件示例
- PHP基于IMAP收取郵件的方法示例
相關(guān)文章
PHP直接修改表內(nèi)容DataGrid功能實(shí)現(xiàn)代碼
最近想做一個(gè)通過(guò)PHP實(shí)現(xiàn)DataGrid功能的東西,這樣可以直接修改數(shù)據(jù)庫(kù)中表的內(nèi)容,而不用開發(fā)【新增數(shù)據(jù)頁(yè)面】和【編輯頁(yè)面】,本篇首先介紹基于MySQL的使用方法,再簡(jiǎn)單介紹對(duì)于Oracle連接(基于sqlrelay)的二次開發(fā)。2015-09-09
PHP將Excel導(dǎo)入數(shù)據(jù)庫(kù)及數(shù)據(jù)庫(kù)數(shù)據(jù)導(dǎo)出至Excel的方法
這篇文章主要介紹了PHP將Excel導(dǎo)入數(shù)據(jù)庫(kù)及數(shù)據(jù)庫(kù)數(shù)據(jù)導(dǎo)出至Excel的方法,涉及php操作數(shù)據(jù)庫(kù)及Excel的相關(guān)技巧,需要的朋友可以參考下2015-06-06
php面向?qū)ο缶幊蘳elf和static的區(qū)別
這篇文章主要介紹了PHP中static關(guān)鍵字以及與self關(guān)鍵字的區(qū)別,本文講解了static關(guān)鍵字的定義、遲綁定(Late Static Bindings)、以及與self關(guān)鍵字的區(qū)別等內(nèi)容,需要的朋友可以參考下2016-05-05
微信公眾號(hào)開發(fā)之通過(guò)接口刪除菜單
本文主要介紹了微信公眾號(hào)通過(guò)接口刪除菜單的方法,具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02
PHP XML error parsing SOAP payload on line 1
PHP中GBK頁(yè)面調(diào)用WebService的編碼問(wèn)題:XML error parsing SOAP payload on line 12010-06-06
PHP mysqli_free_result()與mysqli_fetch_array()函數(shù)詳解
這篇文章主要介紹了PHP mysqli_free_result()與mysqli_fetch_array()函數(shù)詳解的相關(guān)資料,需要的朋友可以參考下2016-09-09

