Php does not provide a ready-made smtp function, but provides a mail () function that is not very flexible. This function requires support on server configuration and does not support smtp verification, it is not recommended because it cannot work normally in many occasions. The purpose of this article is to indicate the direction for new users and not to involve those advanced content. First, the level is limited. Second, I am worried that related concepts cannot be accurately described, which in turn leads to misleading, also, please study in depth. This article was written on July 15, July 2, 2004. Please pay attention to timeliness when reading this article.
"Using php to send mail" has recently become the second newbie trap in this version after "register_globals". Today, I write this article to help beginners solve their problems and hope to give directions to confused people.
Let's start with the following example:
Reference:
[Root @ server ~ /] # Telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server.domain.com.br ESMTP Postfix (2.1.0)
Mail from: teste@dominio.com.br
250 OK
Rcpt to: teste@dominio.com.br
250 OK
DATA
354 End data with <CR> <LF>. <CR> <LF>
Teste
.
250 OK: queued as 7B41F4665A
QUIT
221 Bye
Connection closed by foreign host.
Note: The above postfix documents from netkiller are lazy and ready for use directly.
First, telnet is used to connect to the local port 25. Anyone familiar with the network knows that the smtp protocol uses port 25, which means that the local smtp server is connected now.
Reference:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server.domain.com.br ESMTP Postfix (2.1.0)
These are system output information, indicating that the smtp server has been connected and is postfix.
The "mail from: teste@dominio.com.br" command specifies that the sending address is a teste@dominio.com.br, and "250 OK" indicates that this command is accepted and correctly executed by the server, this is similar to the status code of http 200, 404, and 500. The next "rcpt to: teste@dominio.com.br" specifies that the recipient address is a teste@dominio.com.br.
Reference:
DATA
354 End data with <CR> <LF>. <CR> <LF>
Teste
.
After entering "DATA", the system prompts "<Press Enter>. <Press Enter>" to end the input. The body is "teste ".
Use "QUIT" to exit.
The above is the simplest process of sending mail. From this example, we can see that sending mail is actually a very simple thing. In essence, it is to establish a connection to the smtp server, then, you can send some simple commands to it, and a simple email is sent. As for emails or operations with more complex content, it is actually a little extended on this basis.