Home Backend Development PHP Tutorial 发送mime邮件类_PHP

发送mime邮件类_PHP

Jun 01, 2016 pm 12:37 PM
name th send mail

if(basename($PHP_SELF)== "class.html_mime_mail.inc")
{
  include  "fileinfo.inc";
  echo  "

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

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

<br>

    如果不含圖檔:<br>

     \$mail = new html_mime_mail();<br>

     \$html =\"HTML內容\";<br>

     \$mail->add_html(\$html, \$text);<br>

     \$mail->build_message();<br>

     \$mail->send(收信人,收信Email,發信人,發信Email,標題,額外Header);<br>

<br>

    <hr><br>

    如果含圖檔:<br>

    \$url=\"www.cuti.com.my/AD/\";    //圖檔位?FONT color="#007700">} ?FONT color="#007700">}頭無http:// 結尾有斜線<br>

    \$path=\"/MAIL/AD/\";    //圖檔路徑 結尾有斜線<br>

<br>

    \$filename1 = 'a.jpg';<br>

    \$backgrnd1 = fread(\$fp = fopen(\$path.\$filename1, 'r'), filesize(\$path.\$filename1));<br>

    fclose(\$fp);<br>

    ...依此類推...<br>

    \$filename6 = 'f.gif';<br>

        \$backgrnd6 = fread(\$fp = fopen(\$path.\$filename6, 'r'), filesize(\$path.\$filename6));<br>

        fclose(\$fp);<br>

    <br>

    \$mail->add_html_image(\$backgrnd1,\$filename1,'image/jpeg','http://'.\$url.\$filename1);<br>

    ...依此類推...<br>

    \$mail->add_html_image(\$backgrnd6,\$filename6,'image/gif','http://'.\$url.\$filename6);<br>

<br>

     \$mail = new html_mime_mail();<br>

     \$html =\"HTML含圖內容\";<br>

     \$mail->add_html(\$html, \$text);<br>

     \$mail->build_message();<br>

     \$mail->send(收信人,收信Email,發信人,發信Email,標題,額外Header);<br>

  ";<br>

        <br>

}<br>

/***************************************<br>

** Title.........: HTML Mime Mail class<br>

** Version.......: 1.26<br>

** Author........: Richard Heyes <richard.heyes><br>

** Filename......: html_mime_mail.class<br>

** Last changed..: 25/06/2000<br>

** Notes.........: Based upon mime_mail.class<br>

**                 by Tobias Ratschiller <tobias><br>

**                 and Sascha Schumann <sascha>.<br>

**                  - Thanks to Thomas Flemming for supplying a fix<br>

**                    for Win32.<br>

**                  - Made headers terminated by CRLF instead of LF, now<br>

**                    compliant with RFC822. Thanks to Pao-Hsi Huang.<br>

**                  - Fixed bug; certain mail systems (gmx.net in particular)<br>

**                    were rejecting mail because of a space character either<br>

**                    side of the equal sign on the boundary line. Thanks to<br>

**                    Peter Holm for notifying me.<br>

**                  - Fixed bug; $html_images was tested to be an array or not<br>

**                    but was set to be an array during object creation, so the<br>

**                    test always returned true. Thanks to Bob Silva for<br>

**                    notifying me.<br>

**                  - Fixed bug; when looping with $obj->send(), From: headers<br>

**                    were accumulating. Bummer. Thanks to Lance Rasmussen for<br>

**                    notifying me.<br>

**                  - See http://www.heyes-computing.net/scripts/ for a zip/tar<br>

**                    containing an example script.<br>

***************************************/ <br>

<br>

class html_mime_mail{<br>

<br>

        var $headers;<br>

        var $body;<br>

        var $multipart;<br>

        var $mime;<br>

        var $html;<br>

        var $html_text;<br>

        var $html_images = array();<br>

        var $cids = array();<br>

        var $do_html;<br>

        var $parts = array();<br>

<br>

/***************************************<br>

** Constructor function. Sets the headers<br>

** if supplied.<br>

***************************************/ <br>

        function html_mime_mail($headers =  '){<br>

                $this->headers = $headers;<br>

        }<br>

<br>

/***************************************<br>

** Adds a html part to the mail.<br>

** Also replaces image names with<br>

** content-id's.<br>

***************************************/ <br>

        function add_html($html, $text){<br>

                $this->do_html = 1;<br>

                $this->html = $html;<br>

                $this->html_text = $text;<br>

                if(is_array($this->html_images) AND count($this->html_images) > 0){<br>

                 /*      for($i=0; $i<count>html_images); $i++){<br>

                                $this->html = ereg_replace($this->html_images[$i]['name'], 'cid:'.$this->html_images[$i]['cid'], $this->html);<br>

                        }<br>

        */ <br>

                }<br>

        }<br>

<br>

/***************************************<br>

** Builds html part of email.<br>

***************************************/ <br>

        function build_html($orig_boundary){<br>

                $sec_boundary =  '=_'.md5(uniqid(time()));<br>

                $thr_boundary =  '=_'.md5(uniqid(time()));<br>

<br>

                if(count($this->html_images) == 0){<br>

                        $this->multipart.=  '--'.$orig_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: multipart/alternative;'.chr(10).chr(9). 'boundary="'.$sec_boundary. "\"\n\n\n";<br>

<br>

// ttj added below <br>

                        $this->multipart.=  '--'.$thr_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: text/plain'. "\n\n";<br>

                        $this->multipart.= $this->html_text. "\n\n";<br>

                        $this->multipart.=  '--'.$thr_boundary. "--\n\n";<br>

// ttj added above <br>

                        $this->multipart.=  '--'.$sec_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: text/plain'. "\n";<br>

                        $this->multipart.=  'Content-Transfer-Encoding: base64'. "\n\n";<br>

                        $this->multipart.= chunk_split(base64_encode($this->html_text)). "\n\n";<br>

// ttj added below <br>

                        $this->multipart.=  '--'.$thr_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: text/html'. "\n\n";<br>

                        $this->multipart.= $this->html. "\n\n";<br>

                        $this->multipart.=  '--'.$thr_boundary. "--\n\n";<br>

// ttj added above <br>

<br>

                        $this->multipart.=  '--'.$sec_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: text/html'. "\n";<br>

                        $this->multipart.=  'Content-Transfer-Encoding: base64'. "\n\n";<br>

                        $this->multipart.= chunk_split(base64_encode($this->html)). "\n\n";<br>

                        $this->multipart.=  '--'.$sec_boundary. "--\n\n";<br>

                }else{<br>

                        $this->multipart.=  '--'.$orig_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: multipart/related;'.chr(10).chr(9). 'boundary="'.$sec_boundary. "\"\n\n\n";<br>

<br>

                        $this->multipart.=  '--'.$sec_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: multipart/alternative;'.chr(10).chr(9). 'boundary="'.$thr_boundary. "\"\n\n\n";<br>

<br>

                        $this->multipart.=  '--'.$thr_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: text/plain'. "\n";<br>

                        $this->multipart.=  'Content-Transfer-Encoding: base64'. "\n\n";<br>

                        $this->multipart.= chunk_split(base64_encode($this->html_text)). "\n\n";<br>

<br>

// ttj added below <br>

                        $this->multipart.=  '--'.$thr_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: text/html'. "\n\n";<br>

                        $this->multipart.= $this->html. "\n\n";<br>

                        $this->multipart.=  '--'.$thr_boundary. "--\n\n";<br>

// ttj added above <br>

<br>

                        $this->multipart.=  '--'.$thr_boundary. "\n";<br>

                        $this->multipart.=  'Content-Type: text/html'. "\n";<br>

                        $this->multipart.=  'Content-Transfer-Encoding: base64'. "\n\n";<br>

                        $this->multipart.= chunk_split(base64_encode($this->html)). "\n\n";<br>

                        $this->multipart.=  '--'.$thr_boundary. "--\n\n";<br>

<br>

                        for($i=0; $i<count>html_images); $i++){<br>

                                $this->multipart.=  '--'.$sec_boundary. "\n";<br>

                                $this->build_html_image($i);<br>

                        }<br>

<br>

                        $this->multipart.=  "--".$sec_boundary. "--\n\n";<br>

                }<br>

        }<br>

/***************************************<br>

** Adds an image to the list of embedded<br>

** images.<br>

***************************************/ <br>

        function add_html_image($file, $name =  ', $c_type= 'application/octet-stream', $location= '){<br>

                $this->html_images[] = array(  'body' => $file,<br>

                                               'name' => $name,<br>

                                               'c_type' => $c_type,<br>

                           'location' => $location,<br>

                                               'cid' => md5(uniqid(time())) );<br>

        }<br>

<br>

<br>

/***************************************<br>

** Adds a file to the list of attachments.<br>

***************************************/ <br>

        function add_attachment($file, $name =  ', $c_type= 'application/octet-stream'){<br>

                $this->parts[] = array(  'body' => $file,<br>

                                         'name' => $name,<br>

                                         'c_type' => $c_type );<br>

        }<br>

<br>

/***************************************<br>

** Builds an embedded image part of an<br>

** html mail.<br>

***************************************/ <br>

        function build_html_image($i){<br>

                $this->multipart.=  'Content-Type: '.$this->html_images[$i][ 'c_type'];<br>

<br>

                if($this->html_images[$i][ 'name'] !=  ') $this->multipart .=  '; name="'.$this->html_images[$i][ 'name']. "\"\n";<br>

                else $this->multipart .=  "\n";<br>

<br>

                $this->multipart.=  'Content-Transfer-Encoding: base64'. "\n";<br>

        $this->multipart.=  'Content-Location:'.$this->html_images[$i][ 'location']. "\n";<br>

                $this->multipart.=  'Content-ID: html_images[$i][ 'cid']. ">\n\n";<br>

                $this->multipart.= chunk_split(base64_encode($this->html_images[$i][ 'body'])). "\n";<br>

        }<br>

<br>

/***************************************<br>

** Builds a single part of a multipart<br>

** message.<br>

***************************************/ <br>

        function build_part($i){<br>

                $message_part =  ';<br>

                $message_part.=  'Content-Type: '.$this->parts[$i][ 'c_type'];<br>

                if($this->parts[$i][ 'name'] !=  ')<br>

                        $message_part .=  '; name="'.$this->parts[$i][ 'name']. "\"\n";<br>

                else<br>

                        $message_part .=  "\n";<br>

<br>

                 // Determine content encoding. <br>

                if($this->parts[$i][ 'c_type'] ==  'text/plain'){<br>

                        $message_part.=  'Content-Transfer-Encoding: base64'. "\n\n";<br>

                        $message_part.= chunk_split(base64_encode($this->parts[$i][ 'body'])). "\n";<br>

                }else{<br>

                        $message_part.=  'Content-Transfer-Encoding: base64'. "\n";<br>

                        $message_part.=  'Content-Disposition: attachment; filename="'.$this->parts[$i][ 'name']. "\"\n\n";<br>

                        $message_part.= chunk_split(base64_encode($this->parts[$i][ 'body'])). "\n";<br>

                }<br>

<br>

                return $message_part;<br>

        }<br>

<br>

/***************************************<br>

** Builds the multipart message from the<br>

** list ($this->parts).<br>

***************************************/ <br>

        function build_message(){<br>

                $boundary =  '=_'.md5(uniqid(time()));<br>

<br>

                $this->headers.=  "MIME-Version: 1.0\n";<br>

                $this->headers.=  "Content-Type: multipart/mixed;".chr(10).chr(9). "boundary=\"".$boundary. "\"\n";<br>

                $this->multipart =  ';<br>

//                $this->multipart.= "This is a MIME encoded message.\nCreated by html_mime_mail.class.\nSee http://www.heyes-computing.net/scripts/ for a copy.\n\n"; <br>

<br>

                if(isset($this->do_html) AND $this->do_html == 1) $this->build_html($boundary);<br>

                if(isset($this->body) AND $this->body !=  ') $this->parts[] = array( 'body' => $this->body,  'name' =>  ',  'c_type' =>  'text/plain');<br>

<br>

                for($i=(count($this->parts)-1); $i>=0; $i--){<br>

                        $this->multipart.=  '--'.$boundary. "\n".$this->build_part($i);<br>

                }<br>

<br>

                $this->mime = $this->multipart. "--".$boundary. "--\n";<br>

        }<br>

<br>

/***************************************<br>

** Sends the mail.<br>

***************************************/ <br>

        function send($to_name, $to_addr, $from_name, $from_addr, $subject =  ', $headers =  '){<br>

<br>

                if($to_name !=  ') $to =  '"'.$to_name. '" ';<br>

                else $to = $to_addr;<br>

<br>

                if($from_name !=  ') $from =  '"'.$from_name. '" ';<br>

                else $from = $from_addr;<br>

<br>

                mail($to, $subject, $this->mime,  'From: '.$from. "\n".$headers. "\n".$this->headers);<br>

        }<br>

<br>

/***************************************<br>

** Use this method to deliver using direct<br>

** smtp connection. Relies upon Manuel Lemos'<br>

** smtp mail delivery class available at:<br>

** http://phpclasses.upperdesign.com<br>

**<br>

** void smtp_send( string *Name* of smtp object,<br>

**                 string From address,<br>

**                 array  To addresses,<br>

**                 string Subject)<br>

***************************************/ <br>

        function smtp_send($smtp_obj, $from_addr, $to_addr, $subject){<br>

                global $$smtp_obj;<br>

                $smtp_obj = $$smtp_obj;<br>

<br>

                $this->headers .=  'From: '.$from_addr. "\n";<br>

                $this->headers .=  'Subject: '.$subject. "\n";<br>

<br>

                if(substr($this->headers, -2) ==  "\n") $this->headers = substr($this->headers,0,-2);<br>

                $this->headers = explode( "\n", $this->headers);<br>

<br>

                $smtp_obj->sendmessage($from_addr, $to_addr, $this->headers, $this->mime);<br>

        }<br>

<br>

}  // End of class. <br>

?><br>

 

                 

                     

         

         

         

    </count></count></sascha></tobias></richard.heyes>

Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Outlook emails lost from control panel in Windows 11 Outlook emails lost from control panel in Windows 11 Feb 29, 2024 pm 03:16 PM

Is the Outlook mail icon missing from Windows 11's Control Panel? This unexpected situation has caused confusion and concern among some individuals who rely on OutlookMail for their communication needs. Why don't my Outlook emails show up in Control Panel? There may be several possible reasons why there are no Outlook mail icons in Control Panel: Outlook is not installed correctly. Installing Office applications from the Microsoft Store does not add the Mail applet to Control Panel. The location of the mlcfg32.cpl file in Control Panel is missing. The path to the mlcfg32.cpl file in the registry is incorrect. The operating system is not currently configured to run this application

Say goodbye to the Remote Mail Slot protocol in Windows 11 Say goodbye to the Remote Mail Slot protocol in Windows 11 Apr 14, 2023 pm 10:28 PM

We've been talking lately about the many features Microsoft plans to add to its latest operating system, Windows 11. But don't think that Microsoft will add nothing and take nothing back. In fact, the software giant started removing quite a few old features. After announcing plans to decommission MSDT functionality ahead of the release of Windows 12, a Redmond developer has more bad news. We are actually talking about remote mail slot legacy tool. Trust us when we say you actually want to know this. Microsoft has started deprecating this feature in build 25314. We are sure you remember that just a few days ago, Microsoft released build 25314 in its new canary channel. The above version contains many new features

Word mail merge prints blank page Word mail merge prints blank page Feb 19, 2024 pm 04:51 PM

If you find that blank pages appear when printing a mail merge document using Word, this article will help you. Mail merge is a convenient feature that allows you to easily create personalized documents and send them to multiple recipients. In Microsoft Word, the mail merge feature is highly regarded because it helps users save time manually copying the same content for each recipient. In order to print the mail merge document, you can go to the Mailings tab. But some Word users have reported that when trying to print a mail merge document, the printer prints a blank page or doesn't print at all. This may be due to incorrect formatting or printer settings. Try checking the document and printer settings and make sure to preview the document before printing to ensure the content is correct. if

PHP sends emails asynchronously: avoid long waits for emails to be sent. PHP sends emails asynchronously: avoid long waits for emails to be sent. Sep 19, 2023 am 09:10 AM

PHP sends emails asynchronously: avoid long waits for emails to be sent. Introduction: In web development, sending emails is one of the common functions. However, since sending emails requires communication with the server, it often causes users to wait for a long time while waiting for the email to be sent. In order to solve this problem, we can use PHP to send emails asynchronously to optimize the user experience. This article will introduce how to implement PHP to send emails asynchronously through specific code examples and avoid long waits. 1. Understanding sending emails asynchronously

How to send files to others on TikTok? How to delete files sent to others? How to send files to others on TikTok? How to delete files sent to others? Mar 22, 2024 am 08:30 AM

On Douyin, users can not only share their life details and talents, but also interact with other users. In this process, sometimes we need to send files to other users, such as pictures, videos, etc. So, how to send files to others on Douyin? 1. How to send files to others on Douyin? 1. Open Douyin and enter the chat interface where you want to send files. 2. Click the &quot;+&quot; sign in the chat interface and select &quot;File&quot;. 3. In the file options, you can choose to send pictures, videos, audio and other files. After selecting the file you want to send, click &quot;Send&quot;. 4. Wait for the other party to accept your file. Once the other party accepts it, the file will be transferred successfully. 2. How to delete files sent to others on Douyin? 1. Open Douyin and enter the text you sent.

WhatsApp Tips: How to Send HD Photos and Videos WhatsApp Tips: How to Send HD Photos and Videos Sep 10, 2023 am 10:13 AM

WhatsApp has launched a new option that allows users to send photos and videos in high resolution through the messaging platform. Read on to find out how it's done. WhatsApp has released an update that allows iPhone and Android users to send photos and videos in high resolution, finally addressing the service's low-quality media sharing limitations. The option is called "HD Quality" and means users can send clearer photos and videos with minimal compression. For example, images captured on the iPhone can now be sent at 3024x4032 resolution instead of the previous maximum of 920x1280, while videos can be sent at 1280×718 resolution instead of 848×476.

How to Fix Outlook Email Stuck in Outbox Issue How to Fix Outlook Email Stuck in Outbox Issue May 01, 2023 am 10:01 AM

Recently, many users have reported the issue of Outlook emails getting stuck in the outbox. Even after several attempts to send the email, the issue was not resolved. When you see this issue and check your outbox folder, the message will be stuck there. Possible reasons for emails getting stuck in Outlook outbox: The attachments in the email exceed the size limit, which slows down the sending process. Outlook account authentication issues with mail server Incorrect send/receive settings in Outlook or mail server offline Outlook. Outlook data files are being used by some other software. Antivirus software scans outgoing emails. If this problem has been bothering you and you are unable to send an email

PHP email tracking function: understand user behavior and feedback on emails. PHP email tracking function: understand user behavior and feedback on emails. Sep 19, 2023 am 08:51 AM

PHP email tracking function: understand user behavior and feedback on emails In modern society, email has become an indispensable part of people's daily life and work. For businesses, sending emails is one of the important ways to communicate with customers and promote products or services. However, after an email is sent, how do we know whether it was received, read, or how the user reacted to the content of the email? At this time, the email tracking function becomes particularly important. The email tracking function can help us understand user behavior and feedback on emails

See all articles