Because php does not provide a ready-made smtp function, it provides a mail () function with less flexible functions. this function requires server configuration support and does not support smtp verification.
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.
"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:
- [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 .
- Teste
- .
- 250 OK: queued as 7B41F4665A
- QUIT
- 221 Bye
- Connection closed by foreign host.
Note: The postfix document from netkiller is lazy and is ready for use. first, telnet is used to connect to the local port 25. anyone familiar with the network knows that the smtp protocol uses port 25, this is to say, now connecting to the local smtp server, 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 .
- Teste
- .
This section is the body of the email. after entering "DATA", the system prompts you to use" <回车> . <回车> "To end the input, the body is" teste ", and then exit with" QUIT.
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, send some simple commands to it, and a simple email is sent out. as for emails or operations with more complex content, it is actually a little extended on this basis.