The code for sending mails using SMTP in php the latest project needs to use SMTP to send mails. the previous library class does not exist and does not like to install pear or use the net/smtp class of pear, it is too complicated. The core is extracted from discuz and slightly modified.
Find the SMTP protocol commands and responses from the Protocol Analysis Network, the session between sending SMTP and receiving SMTP protocol is completed by sending SMTP commands and receiving SMTP feedback responses. Common commands are as follows:
HELLO <domain> <CRLF> identifies a HELLO command sent by the sender to receive SMTP
Mail from: <reverse-path> <CRLF> <reverse-path> is the sender address. This command informs the recipient of the start of sending a new mail and initializes all statuses and buffers. This command starts a mail transmission process and finally delivers mail data to one or more mailboxes.
Rcpt to: <forward-path> <CRLF> <forward-path> identifies the addresses of each email recipient
DATA <CRLF>
After receiving SMTP, the behavior is treated as mail data, ending with <CRLF>. <CRLF> identifying data.
REST <CRLF> exit/reset the current email transmission
NOOP <CRLF> requires that only OK responses are received for SMTP. (For testing)
QUIT <CRLF> requires receiving SMTP to return an OK response and disable transmission.
VRFY <string> <CRLF> verifies whether the specified email address exists. This command is not allowed on the server due to security reasons.
EXPN <string> <CRLF> verifies whether the specified email address list exists and expands the email address list.
HELP <CRLF> query commands supported by the server
Note: <CRLF> the carriage return and line feed are supported, and the ASCII code is 13 and 10 (decimal), respectively ).
In addition, you can use telnet to manually use SMTP in command.
For example:
Telnet smtp.263.net 25
Trying 211.150.96.25...
Connected to smtp.263.net.
Escape character is '^]'.
220 Welcome to coremail System (With Anti-Spam) 2.1 for 263 (040326)
HELO weiqiong@cctk.net
250 smtp.263.net
Mail from: weiqiong@cctk.net
250 OK
Rcpt to: g2_t1@263.net
250 OK
Data
354 End data .
Haha
.
250 OK: queued as B9E452FF3E
Quit
221 Bye
Connection closed by foreign host.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.