Sending email using Socket 1_PHP tutorial

WBOY
Release: 2016-07-13 17:28:15
Original
737 people have browsed it

Among the several PHP homepage spaces that the author has applied for, there are not many that can provide mail functions. There is always nothing to do after calling the mail() function. But email plays a growing role in online life. Think about it, can an internet bug be called a real internet bug if he surfs the Internet without receiving emails? I don’t want to talk about the role of email anymore, but what should I do if the homepage space does not support mail() sending? I have also thought about sending emails through sockets, but unfortunately I am not familiar with socket programming using PHP. In addition, sending emails requires the SMTP protocol and requires reading a lot of English, so I have never studied it. Finally one day I found an article about using socket programming to send emails. I copied it as if I had found a treasure, and transformed it into a class available in PHP for everyone to use. The original article was just a simple example, and there were some errors. After many experiments and transformations, I finally changed it into a class that directly uses sockets to send emails to specified mailboxes. If you follow the previous instructions about sending By combining MIME articles, you can send emails on websites that do not support the mail() function. Because the process of sending emails takes time, it may not be exactly the same as the processing mechanism of mail(), so the speed is slower, but it can solve the urgent need to send emails. At the same time, you can also learn to use PHP for socket programming. Next, I will introduce the implementation principle of this class to you, and at the same time explain some basic knowledge about SMTP to you.
Introduction to Socket Programming
I would like to state to everyone that I am not a TCP/IP programming expert, so I am just sharing my understanding and experience here.
Use the fsockopen function to open an Internet connection. The function syntax format is:
int fsockopen(string hostname, int port, int [errno], string [errstr], int [timeout]);
The meaning of the parameters is: Needless to say, since the SMTP protocol is used here, the port number is 25. After the connection is successfully opened, a socket handle will be returned, which can be used like a file handle. Available operations include fputs(), fgets(), feof(), fclose(), etc.
That’s it for a very simple introduction.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531780.htmlTechArticleAmong the several PHP homepage spaces that the author has applied for, there are not many that can provide the mail function. They always call After finishing the mail() function, there is nothing further. But the role of email in online life...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!