20080511
写了一个网站,反馈页面要用到 php 发邮件,无奈网站空间的 php 没有配置可用的邮件服务器,发现 php 也可通过
socket 裸发邮件。配一个可用的帐号,下面函数就可用了。
1 function send_mail( $to , $subject = ' 未标题 ' , $body ){
2 $loc_host = " smtp.126.com " ;
3 $smtp_acc = " youraccount " ;
4 $smtp_pass = " yourpassword " ;
5 $smtp_host = " smtp.126.com " ;
6 $from = " admin@126.com " ;
7
8 $headers = " Content-Type: text/plain; charset=\ " gb2312\ " \r\nContent-Transfer-Encoding:base64 " ;
9 $lb = " \r\n " ;
10 $hdr = explode ( $lb , $headers );
11 if ( $body ){
12 $bdy = preg_replace ( " /^\./ " , " .. " , explode ( $lb , $body ));
13 }
14
15 $smtp = array (
16 array ( " EHLO " . $loc_host . $lb , " 220, 250 " , " HELO error: " ) ,
17 array ( " AUTH LOGIN " . $lb , " 334 " , " AUTH error: " ) ,
18 array ( base64_encode ( $smtp_acc ) . $lb , " 334 " , " AUTHENTIFICATION error: " ) ,
19 array ( base64_encode ( $smtp_pass ) . $lb , " 235 " , " AUTHENTIFICATION error: " )
20 );
21
22 $smtp [] = array ( " MAIL FROM: " . $lb , " 250 " , " MAIL FROM error: " );
23 $smtp [] = array ( " RCPT TO: " . $lb , " 250 " , " RCPT TO error: " );
24 $smtp [] = array ( " DATA " . $lb , " 354 " , " DATA error: " );
25
26 $smtp [] = array ( " From: " . $from . $lb , "" , "" );
27 $smtp [] = array ( " To: " . $to . $lb , "" , "" );
28 $smtp [] = array ( " Subject: " . $subject . $lb , "" , "" );
29
30 foreach ( $hdr as $h ){
31 $smtp [] = array ( $h . $lb , "" , "" );
32 }
33
34 $smtp [] = array ( $lb , "" , "" );
35
36 if ( $bdy ){
37 foreach ( $bdy as $b ){
38 $smtp [] = array ( base64_encode ( $b . $lb ) . $lb , "" , "" );
39 }
40 }
41 $smtp [] = array ( " . " . $lb , " 250 " , " DATA(end) error: " );
42 $smtp [] = array ( " QUIT " . $lb , " 221 " , " QUIT error: " );
43
44 $fp = (@ fsockopen ( $smtp_host , 25 ));
45 if ( ! $fp ) echo " Error: Cannot connect to " . $smtp_host . "
" ;
46 while ( $result = @ fgets ( $fp , 1024 )){
47 if ( substr ( $result , 3 , 1 ) == " " ){ break ; }
48 }
49 $result_str = "" ;
50 foreach ( $smtp as $req ){
51 @ fputs ( $fp , $req [ 0 ]);
52 if ( $req [ 1 ]){
53 while ( $result = @ fgets ( $fp , 1024 )){
54 if ( substr ( $result , 3 , 1 ) == " " ){ break ; }
55 }
56 if ( ! strstr ( $req [ 1 ] , substr ( $result , 0 , 3 ))){
57 $result_str .= $reg [ 2 ] . $result . "
" ;
58 }
59 }
60 }
61 @ fclose ( $fp );
62 return $result_str ;
63 }
64
65

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Alipay PHP...

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
