Phpsocket basic mail class php socket basic mail class, fsocketopen pfsocketopen is generally disabled by space service providers.
In this case, you can use the SMTP protocol to connect and communicate with the mail server using socket_create and socket_connect.
For smtp, you can search for the format of a sent email.
A problem that you have noticed when writing this code. do not use single quotation marks when sending commands with the mail service. for example, use double quotation marks"
Otherwise, the email server does not recognize the command. For example, the command "ehlo helo \ r \ n ", this is because \ r \ n must be added to each command. If \ r \ n is enclosed in single quotes, it will be sent as a character without a carriage return.
This class has been integrated into the phpx (self-written PHP lightweight framework) framework,
If you are interested, you can get the local test. the status code and description returned by the email server when you communicate with the email server are displayed during running.
Smtp status code and description http://my.oschina.net/apeng/blog/119627
Smtp = $ array [0]; $ this-> port = $ array [1]; $ this-> from = $ array [2]; $ this-> pass = $ array [3]; $ this-> to = $ array [4];} public function send ($ header = null, $ body = null) {$ this-> socket = socket_create (AF_INET, SOCK_STREAM, getprotobyname ('tcp '); if (! $ This-> socket) {$ this-> log ('failed to create socket ', true);} if (socket_connect ($ this-> socket, $ this-> smtp, $ this-> port) {$ this-> log ('server connection response :'. socket_strerror (socket_last_error ();} else {$ this-> log ('socket connection failed', true );} $ this-> data = "ehlo helo \ r \ n"; $ this-> do_send (); $ this-> data = "auth login \ r \ n "; $ this-> do_send (); $ this-> data = base64_encode ($ this-> from ). "\ r \ n"; $ this-> do_send (); $ this-> data = base64_encode ($ this-> pass ). "\ r \ n"; $ this-> do_send (); $ this-> data = "mail from: <". $ this-> from. "> \ r \ n"; $ this-> do_send (); $ this-> data = "rcpt to: <". $ this->. "> \ r \ n"; $ this-> do_send (); $ this-> data = "DATA \ r \ n"; $ this-> do_send (); $ this-> data = "From: Anonymous <". $ this-> from. "> \ r \ n"; $ this-> data. = "Subject :". $ header. "\ r \ n"; $ this-> data. = $ body. "\ r \ n. \ r \ n "; $ this-> do_send (); $ this-> data =" QUIT \ r \ n "; $ this-> do_send (); socket_close ($ this-> socket);} public function do_send () {socket_write ($ this-> socket, $ this-> data, strlen ($ this-> data )); $ this-> log ('Client sending :'. $ this-> data); $ this-> log ('server response :'. socket_read ($ this-> socket, 1024 )).'
';} Public function log ($ args = null, $ exit = false) {echo $ args .'
'; If ($ exit = true) {exit ;}}?>