-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.php
More file actions
96 lines (78 loc) · 1.99 KB
/
mail.php
File metadata and controls
96 lines (78 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* bool
* 30024167@qq.com
* Mail 邮件发送
*/
class Mail
{
protected $config;
function __construct($config)
{
$this->config = $config;
}
public function send($to_user,$subject,$content)
{
// 判断是否使用html类型
$type = $this->config['html'] ? 'Content-type: text/html;' : 'Content-type: text/plain;';
$cmd = [
"EHLO {$this->config['smtp_name']}\r\n",
"AUTH LOGIN\r\n",
base64_encode($this->config['smtp_user'])."\r\n",
base64_encode($this->config['smtp_pass'])."\r\n",
"MAIL FROM: <{$this->config['smtp_user']}>\r\n",
"RCPT TO: <{$to_user}>\r\n",
"DATA\r\n",
"From: \"{$this->config['smtp_name']}\"<{$this->config['smtp_user']}>\r\n",
"To: <{$to_user}>\r\n",
"Subject:{$subject}\r\n",
$type."\r\n",
"\r\n",
$content." \r\n",
".\r\n",
"QUIT\r\n",
];
$this->connect($cmd);
return true;
}
// 链接 发送
protected function connect($cmd)
{
//打开smtp服务器端口
$fp = @pfsockopen($this->config['smtp_host'], $this->config['smtp_port']);
$fp or die("Error: Cannot conect to ".$smtp_host);
// 执行命令
foreach ($cmd as $k => $v) {
@fputs($fp, $v );
// ************ 打印 ***********
$res= fgets($fp);
echo "\n {$v} {$res} \n";
// *****************************
// sleep(1);
// 延迟 0.5秒
usleep(500000);
}
}
}
// 使用
// 网易
// $config = [
// 'smtp_host' => 'smtp.163.com',
// 'smtp_port' => 25,
// 'smtp_user' => 'bool1993@163.com',
// 'smtp_pass' => '****',
// 'smtp_name' => 'bool',
// 'html' => true,
// ];
// 2980
// $config = [
// 'smtp_host' => 'smtp.2980.com',
// 'smtp_port' => 25,
// 'smtp_user' => 'bool1993@2980.com',
// 'smtp_pass' => '*******',
// 'smtp_name' => 'bool',
// 'html' => true,
// ];
$mail = new Mail($config);
$mail->send('bool1993@qq.com','subject123',' <h1>333333333333333</h1> <br> <a href="http://www.baidu.com"> baidu</a> <hr>')
?>