public procedure Execute; override; end; TService1 = class(TService) procedure ServiceStart(Sender: TService; var Started: Boolean); procedure ServiceContinue(Sender: TService; var Continued: Boolean); procedure ServicePause(Sender: TService; var Paused: Boolean); procedure ServiceStop(Sender: TService; var Stopped: Boolean); private { Private declarations } public function GetServiceController: TServiceController; override; { Public declarations } end;var Service1: TService1;implementation{$R *.DFM} var
SnakeThread: TSnakeThread;procedure ServiceController(CtrlCode: DWord); stdcall; begin Service1.Controller(CtrlCode); end;function TService1.GetServiceController: TServiceController; begin Result := ServiceController; end; procedure TSnakeThread.Execute;
begin while not Terminated do begin //发送mail程序
Sleep(1000);//间隔时间 end; end;procedure TService1.ServiceStart(Sender: TService; var Started: Boolean); begin SnakeThread := TSnakeThread.Create(False); Started := True; end;procedure TService1.ServiceContinue(Sender: TService; var Continued: Boolean); begin SnakeThread.Resume; Continued := True; end;procedure TService1.ServicePause(Sender: TService; var Paused: Boolean); begin SnakeThread.Suspend; Paused := True;end;procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean); begin SnakeThread.Terminate; Stopped := True; end;end.
根据 snake1220() 前辈提供的代码我调试老出问题,请帮忙解答下啊:(就是前辈提供的refresh.php 这段程序) 运行后: Warning: Missing argument 1 for smtp_mail() in /www/smtp.php on line 16Warning: Missing argument 2 for smtp_mail() in /www/smtp.php on line 16Warning: Missing argument 3 for smtp_mail() in /www/smtp.php on line 16Warning: Missing argument 4 for smtp_mail() in /www/smtp.php on line 16Fatal error: Call to undefined function: socket_create() in /www/smtp.php on line 23就是这两行有问题: “function smtp_mail($host,$port,$user,$pass,$debug=false) ” “$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //具体用法请参考手册 ”不太明白怎么调试,前辈们请指点讲讲啊!!!!谢谢了!!!!!!!!!!!!
不过10W条发起来很慢的。
ice_berg16(寻梦的稻草人) 老大,phpmailer 是啥??
成功率高就是慢点
refresh.php
-----------------------------------------
<?
require "smtp.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="refresh" content="10; url=refresh.php">
<title>无标题文档</title>
</head><body>
<?
//每刷新一次换一个mail地址
$smtp = new smtp_mail;
$smtp->send("test","mail地址","title","content");
?>
</body>
</html>smtp.php
------------------------------------<?php
class smtp_mail
{
var $host; //主机
var $port; //端口 一般为25
var $user; //SMTP认证的帐号
var $pass; //认证密码
var $debug = false; //是否显示和服务器会话信息?
var $conn;
var $result_str; //结果
var $in; //客户机发送的命令
var $from; //源信箱
var $to; //目标信箱
var $subject; //主题
var $body; //内容
function smtp_mail($host,$port,$user,$pass,$debug=false)
{
$this->host = "smtpserver";
$this->port = "25";
$this->user = base64_encode("admin_mail");
$this->pass = base64_encode("密码");
$this->debug = false;
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //具体用法请参考手册
if($this->socket)
{
$this->result_str = "创建SOCKET:".socket_strerror(socket_last_error());
$this->debug_show($this->result_str);
}
else
{
exit("初始化失败,请检查您的网络连接和参数");
}
$this->conn = socket_connect($this->socket,$this->host,$this->port);
if($this->conn)
{
$this->result_str = "创建SOCKET连接:".socket_strerror(socket_last_error());
$this->debug_show($this->result_str);
}
else
{
exit("初始化失败,请检查您的网络连接和参数");
}
$this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
$this->debug_show($this->result_str);
}
function debug_show($str)
{
if($this->debug)
{
echo $str."<p>\r\n";
}
}
function send($from,$to,$subject,$body)
{
if($from == "" || $to == "")
{
exit("请输入信箱地址");
}
if($subject == "") $subject = "无标题";
if($body == "") $body = "无内容";
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body; $All .= "From:".$this->from."\n";
$All .= "To:".$this->to."\n";
$All .= "Subject:".$this->subject."\r\n";
//$All .= $this->body;
$All .= "X-Priority: 3\r\n";
$All .= "X-MSMail-Priority: Normal\r\n";
$All .= "Content-Transfer-Encoding: 8bit\r\n";
$All .= "MIME-Version: 1.0\r\n";
$All.= "Date: ".date("r")."\r\n";
$All.= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$All.= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$this->from.">\r\n";$All .= "Content-Type: text/html\r\n";
$All .= "X-Brightmail-Tracker: AAAAAQAAAAQ=\r\n";
$All .= "Resent-Message-Id: <44714DA9.04DBDB.21903>\r\n";
$All .= "Resent-Date: ".date("r")."\r\n";
$All.=$this->body."\r\n\r\n";/*
如过把$All的内容再加处理,就可以实现发送MIME邮件了
不过还需要加很多程序
*/
//------------------------------------
/*
$All.="Mime-Version: 1.0\r\nContent-type: Multipart/mix;\r\n";
$All.="\tboundary=\"=====000_Dragon2722284863_=====\"";//定义分割字符串$All.="\r\n\r\nThis is a multi-part message in MIME format";$All.="\r\n\r\n--=====000_Dragon2722284863_=====\r\n";//分割("--"加上定义的分割字符串)
$All.="Content-type: text/plain;\r\n\tcharset=\"GB2312\"\r\n";
$All.="Content-transfer-encoding: 8bit\r\n\r\n";
$All.=$this->body."\r\n\r\n";
$All.="\r\n\r\n--=====000_Dragon2722284863_=====\r\n";//分割("--"加上定义的分割字符串)
$All.="Content-type: text/html;\r\n\tcharset=\"GB2312\"\r\n";
$All.= "Date: ".date("r")."\r\n";
$All.= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$All.= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$this->from.">\r\n";
$All.="Content-transfer-encoding: 8bit\r\n\r\n";$All.=$this->body."\r\n\r\n";
$All.="--=====000_Dragon2722284863_=====--\r\n";//分割
*/
//-----------------------------------//以下是和服务器会话
$this->in = "EHLO HELO\r\n";
$this->docommand(); $this->in = "AUTH LOGIN\r\n";
$this->docommand(); $this->in = $this->user."\r\n";
$this->docommand(); $this->in = $this->pass."\r\n";
$this->docommand(); $this->in = "MAIL FROM:".$this->from."\r\n";
$this->docommand(); $this->in = "RCPT TO:".$this->to."\r\n";
$this->docommand(); $this->in = "DATA\r\n";
$this->docommand(); $this->in = $All."\r\n.\r\n";
$this->docommand(); $this->in = "QUIT\r\n";
$this->docommand(); //结束,关闭连接 }
function docommand()
{
socket_write ($this->socket, $this->in, strlen ($this->in));
$this->debug_show("客户机命令:".$this->in);
$this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
$this->debug_show($this->result_str);
}
}
?>
你用socket还不是要循环2万次?而且还更加麻烦。
暂停执行。
语法: void sleep(int seconds);
返回值: 无
函数种类: PHP 系统功能
内容说明
本函数可暂时使程序停止执行。参数 seconds 为要暂停的秒数。
参考
usleep() socket 群发最关键问题就是mail之间得发送时间间隔,如果时间太短 发送成功率非常非常低如果非要循环发送在循环里面必须加上sleep(seconds)因为这种方法执行时间太长,所有我没有用过,我目前就是用refresh,把这个文件放在我们管理平台上,这样当几个用户打开管理平台得时候就类似一个 多线程程序,用着挺好.还有一个方法就是写一个系统服务
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;type
TSnakeThread = class(TThread)
public
procedure Execute; override;
end; TService1 = class(TService)
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceContinue(Sender: TService; var Continued: Boolean);
procedure ServicePause(Sender: TService; var Paused: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;var
Service1: TService1;implementation{$R *.DFM}
var
SnakeThread: TSnakeThread;procedure ServiceController(CtrlCode: DWord); stdcall;
begin
Service1.Controller(CtrlCode);
end;function TService1.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TSnakeThread.Execute;
begin
while not Terminated do
begin
//发送mail程序
Sleep(1000);//间隔时间
end;
end;procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);
begin
SnakeThread := TSnakeThread.Create(False);
Started := True;
end;procedure TService1.ServiceContinue(Sender: TService;
var Continued: Boolean);
begin
SnakeThread.Resume;
Continued := True;
end;procedure TService1.ServicePause(Sender: TService; var Paused: Boolean);
begin
SnakeThread.Suspend;
Paused := True;end;procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
SnakeThread.Terminate;
Stopped := True;
end;end.
发送需要回执的邮件,对方点开邮件,本地系统接收对方回执邮件?就像OutLook发送邮件的“请求阅读回执”
这个PHP能实现吗??如何做啊 谢谢了!!
运行后:
Warning: Missing argument 1 for smtp_mail() in /www/smtp.php on line 16Warning: Missing argument 2 for smtp_mail() in /www/smtp.php on line 16Warning: Missing argument 3 for smtp_mail() in /www/smtp.php on line 16Warning: Missing argument 4 for smtp_mail() in /www/smtp.php on line 16Fatal error: Call to undefined function: socket_create() in /www/smtp.php on line 23就是这两行有问题:
“function smtp_mail($host,$port,$user,$pass,$debug=false) ”
“$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //具体用法请参考手册 ”不太明白怎么调试,前辈们请指点讲讲啊!!!!谢谢了!!!!!!!!!!!!
还是这样写(mail.abc.com)?