Home  >  Article  >  Backend Development  >  Sending email using Socket 2_PHP tutorial

Sending email using Socket 2_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:28:12895browse


Basics of SMTP
The general command format of the Internet protocol based on TCP/IP is implemented through the request/response method, and all text information is used, so it is easier to process. SMTP is the abbreviation of Simple Mail Transfer Protocol, which enables the client to send emails to the server. So the command mentioned below refers to the client sending a request instruction to the server, and the response refers to the information returned by the server to the client.
SMTP is divided into two parts: command header and message body. The command header mainly completes the connection between the client and the server, verification, etc. The entire process consists of multiple commands. After each command is sent to the server, the server will give response information, usually a 3-digit response code and response text. The response codes returned by different servers adhere to the protocol, but the response text does not. There is a carriage return character at the end of each command and response, so that commands and responses can be processed using fputs() and fgets(). SMTP command and response messages are single lines. The message body is the body of the email, and the final closing line should be ended with a separate "."
Some commonly used SMTP commands on the client are:
HELO hostname: Greet the server and tell the client the machine name used. You can fill it in casually
MAIL FROM: sender_id: Tell the server the address of the sender
RCPT TO: receiver_id: Tell the server the address of the recipient
DATA: Start transmitting the content of the letter and end it with a special line containing only .
RESET: Cancel the previous command and start over
VERIFY userid : Verify whether the account exists (this command is optional and may not be supported by the server)
QUIT : Exit the connection and end
The response information returned by the server is (the format is: response code + space + explanation):
220 Service ready (this information will be returned when the socket connection is successful)
221 Processing
250 The requested email action is correct and completed (HELO, MAIL FROM, RCPT TO, QUIT command is executed successfully and this information will be returned) )
354 Start sending data and end with. (Successful execution of the DATA command will return this information, the client should send the information)
500 Syntax error, the command cannot be recognized
550 The command cannot be executed, the email is invalid


552 Interrupt handling: User exceeded file space

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531793.htmlTechArticleThe basis of SMTP. The general command format of the Internet protocol based on TCP/IP is implemented through the request/response method. All text information is used, so it is easier to process. SMTP is...
Statement:
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