用Socket发送电子邮件(七)_PHP教程
程序员文章站
2024-01-31 00:01:40
...
b>邮件发送处理
下面是真正的秘密了,可要看仔细了。:)
1 function send( $to,$from,$subject,$message)
2 {
3 //连接服务器
4 $this-$#@62;lastact="connect";
5 $this-$#@62;show_debug("Connect to SMTP server : ".$this-$#@62;smtp, "out");
6 $this-$#@62;fp = fsockopen ( $this-$#@62;smtp, $this-$#@62;port );
7 if ( $this-$#@62;fp )
8 {
9 set_socket_blocking( $this-$#@62;fp, true );
10 $this-$#@62;lastmessage=fgets($this-$#@62;fp,512);
11 $this-$#@62;show_debug($this-$#@62;lastmessage, "in");
12 if (! ereg ( "^220", $this-$#@62;lastmessage ) )
13 {
14 return false;
15 }
16 else
17 {
18 $this-$#@62;lastact="HELO " . $this-$#@62;welcome . " ";
19 if(!$this-$#@62;do_command($this-$#@62;lastact, "250"))
20 {
21 fclose($this-$#@62;fp);
22 return false;
23 }
24 $this-$#@62;lastact="MAIL FROM: $from" . " ";
25 if(!$this-$#@62;do_command($this-$#@62;lastact, "250"))
26 {
27 fclose($this-$#@62;fp);
28 return false;
29 }
30 $this-$#@62;lastact="RCPT TO: $to" . " ";
31 if(!$this-$#@62;do_command($this-$#@62;lastact, "250"))
32 {
33 fclose($this-$#@62;fp);
34 return false;
35 }
36 //发送正文
37 $this-$#@62;lastact="DATA ";
38 if(!$this-$#@62;do_command($this-$#@62;lastact, "354"))
39 {
40 fclose($this-$#@62;fp);
41 return false;
42 }
43 //处理Subject头
44 $head="Subject: $subject ";
45 if(!empty($subject) && !ereg($head, $message))
46 {
47 $message = $head.$message;
48 }
49 //处理From头
50 $head="From: $from ";
51 if(!empty($from) && !ereg($head, $message))
52 {
53 $message = $head.$message;
54 }
55 //处理To头
56 $head="To: $to ";
57 if(!empty($to) && !ereg($head, $message))
58 {
59 $message = $head.$message;
60 }
下面是真正的秘密了,可要看仔细了。:)
1 function send( $to,$from,$subject,$message)
2 {
3 //连接服务器
4 $this-$#@62;lastact="connect";
5 $this-$#@62;show_debug("Connect to SMTP server : ".$this-$#@62;smtp, "out");
6 $this-$#@62;fp = fsockopen ( $this-$#@62;smtp, $this-$#@62;port );
7 if ( $this-$#@62;fp )
8 {
9 set_socket_blocking( $this-$#@62;fp, true );
10 $this-$#@62;lastmessage=fgets($this-$#@62;fp,512);
11 $this-$#@62;show_debug($this-$#@62;lastmessage, "in");
12 if (! ereg ( "^220", $this-$#@62;lastmessage ) )
13 {
14 return false;
15 }
16 else
17 {
18 $this-$#@62;lastact="HELO " . $this-$#@62;welcome . " ";
19 if(!$this-$#@62;do_command($this-$#@62;lastact, "250"))
20 {
21 fclose($this-$#@62;fp);
22 return false;
23 }
24 $this-$#@62;lastact="MAIL FROM: $from" . " ";
25 if(!$this-$#@62;do_command($this-$#@62;lastact, "250"))
26 {
27 fclose($this-$#@62;fp);
28 return false;
29 }
30 $this-$#@62;lastact="RCPT TO: $to" . " ";
31 if(!$this-$#@62;do_command($this-$#@62;lastact, "250"))
32 {
33 fclose($this-$#@62;fp);
34 return false;
35 }
36 //发送正文
37 $this-$#@62;lastact="DATA ";
38 if(!$this-$#@62;do_command($this-$#@62;lastact, "354"))
39 {
40 fclose($this-$#@62;fp);
41 return false;
42 }
43 //处理Subject头
44 $head="Subject: $subject ";
45 if(!empty($subject) && !ereg($head, $message))
46 {
47 $message = $head.$message;
48 }
49 //处理From头
50 $head="From: $from ";
51 if(!empty($from) && !ereg($head, $message))
52 {
53 $message = $head.$message;
54 }
55 //处理To头
56 $head="To: $to ";
57 if(!empty($to) && !ereg($head, $message))
58 {
59 $message = $head.$message;
60 }
上一篇: 抽离CodeIgniter的数据库访问类
下一篇: php输出指定时间以前时间格式的方法
推荐阅读
-
用Socket发送电子邮件(七)_PHP教程
-
用Socket发送电子邮件一
-
用phpmailer发送HTML邮件_PHP教程
-
用PHP模拟登录WAP飞信实现飞信发送_PHP教程
-
用PHP即时捕捉PHP中的错误并发送email通知的实现代码_PHP教程
-
用PHP发电子邮件2_PHP教程
-
php 利用socket发送GET,POST请求,socketget_PHP教程
-
用MySQL内建复制来最佳化可用性(七)_PHP教程
-
用PHP即時捕捉PHP原始碼中的錯誤并發送email通知,javaemail发送_PHP教程
-
PHP模拟发送POST请求之三、用Telnet和fsockopen()模拟发送POST信息,telnetfsockopen_PHP教程