首頁 php教程 PHP源码 php Socket发送电子邮箱来验证邮箱的真实有效性而非格式

php Socket发送电子邮箱来验证邮箱的真实有效性而非格式

May 25, 2016 pm 05:15 PM
php socket 傳送 有效性 電子郵件信箱 真實 驗證信箱

验证邮箱的真实性而非格式

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

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

<?php

 

 

set_time_limit(120);

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 = $host;

 $this->port = $port;

 $this->user = base64_encode($user);

 $this->pass = base64_encode($pass);

 $this->debug = $debug;

 $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>rn";

}

}

function send($from,$to,$subject,$body)

{

 if($from ==""|| $to =="")

{

exit("请输入信箱地址");

}

 if($subject =="") $sebject ="无标题";

 if($body =="") $body ="无内容";

 $this->from = $from;

 $this->to = $to;

 $this->subject = $subject;

 $this->body = $body;

 

//扬帆修改部分代码

 $All ="From:<".$this->from.">rn";

 $All .="To:<".$this->to.">rn";

 $All .="Subject:".$this->subject."rnrn";

 $All .= $this->body;

 

 

 

//以下是和服务器会话

 $this->in ="EHLO HELOrn";

$this->docommand();

 

 $this->in ="AUTH LOGINrn";

$this->docommand();

 

 $this->in = $this->user."rn";

$this->docommand();

 

 $this->in = $this->pass."rn";

$this->docommand();

 

// $this->in ="MAIL FROM:".$this->from."rn";

 $this->in ="MAIL FROM:<".$this->from.">rn"; //扬帆修改

$this->docommand();

 

// $this->in ="RCPT TO:".$this->to."rn";

 $this->in ="RCPT TO:<".$this->to.">rn"; //扬帆修改

$this->docommand();

 

 $this->in ="DATArn";

$this->docommand();

 

 $this->in = $All."rn.rn";

$this->docommand();

 

 $this->in ="QUITrn";

$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);

}

}

?>

登入後複製

1

2

3

4

5

6

7

8

9

10

<?php

//测试页面

include"smtp_mail.php";

 

//你用这个类的时候你修改成你自己的信箱就可以了

$smtp=new smtp_mail("smtp.qq.com","25","yourmail@qq.com","Your password",true);

//如果你需要显示会话信息,请将上面的修改成

//$smtp = new smtp_mail("smtp.qq.com","25","你的qq.com的帐号","你的密码",true);

$smtp->send("yourmail@qq.com","yourmail@qq.com","你好","测试邮件");

?>

登入後複製
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
4 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

CakePHP 專案配置 CakePHP 專案配置 Sep 10, 2024 pm 05:25 PM

在本章中,我們將了解CakePHP中的環境變數、常規配置、資料庫配置和電子郵件配置。

適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 Dec 24, 2024 pm 04:42 PM

PHP 8.4 帶來了多項新功能、安全性改進和效能改進,同時棄用和刪除了大量功能。 本指南介紹如何在 Ubuntu、Debian 或其衍生版本上安裝 PHP 8.4 或升級到 PHP 8.4

CakePHP 日期和時間 CakePHP 日期和時間 Sep 10, 2024 pm 05:27 PM

為了在 cakephp4 中處理日期和時間,我們將使用可用的 FrozenTime 類別。

CakePHP 檔案上傳 CakePHP 檔案上傳 Sep 10, 2024 pm 05:27 PM

為了進行文件上傳,我們將使用表單助理。這是文件上傳的範例。

CakePHP 路由 CakePHP 路由 Sep 10, 2024 pm 05:25 PM

在本章中,我們將學習以下與路由相關的主題?

討論 CakePHP 討論 CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP 是 PHP 的開源框架。它旨在使應用程式的開發、部署和維護變得更加容易。 CakePHP 基於類似 MVC 的架構,功能強大且易於掌握。模型、視圖和控制器 gu

如何設定 Visual Studio Code (VS Code) 進行 PHP 開發 如何設定 Visual Studio Code (VS Code) 進行 PHP 開發 Dec 20, 2024 am 11:31 AM

Visual Studio Code,也稱為 VS Code,是一個免費的原始碼編輯器 - 或整合開發環境 (IDE) - 可用於所有主要作業系統。 VS Code 擁有大量針對多種程式語言的擴展,可以輕鬆編寫

CakePHP 建立驗證器 CakePHP 建立驗證器 Sep 10, 2024 pm 05:26 PM

可以透過在控制器中新增以下兩行來建立驗證器。

See all articles