Heim > php教程 > php手册 > Hauptteil

用PHP通过SMTP发送邮件

WBOY
Freigeben: 2016-06-21 08:57:58
Original
886 Leute haben es durchsucht

  由于PHP没有提供现成的smtp函数,却提供了一个功能不甚灵活的mail()函数,这个函数需要服务器配置上的支持,并且不支持smtp验证,在很多场合无法正常的工作,因此不建议使用。本文的目的在于为新手指明方向,并没有涉及那些高级的内容,一来本身水平有限,二来也担心不能准确的讲述相关的概念,进而对各位造成误导,还请自行深入学习。

  “使用php发送mail”最近已经成为继“register_globals”以后本版第二个新手陷阱,今天特地写这篇文章为新手解惑,希望可以为迷茫的人指明方向。

  让我们先从以下这个例子开始说起:

  引用:

[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 .
teste
.
250 Ok: queued as 7B41F4665A
QUIT
221 Bye
Connection closed by foreign host.

  注:以上来自netkiller的postfix文档,偷懒,直接用现成的。

  首先是使用telnet来连接本地的25端口,稍微熟悉点网络的人都知道smtp协议使用25端口,这也就是说,现在在连接本地的smtp服务器。

  引用:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server.domain.com.br ESMTP Postfix (2.1.0)

  这些东西是系统输出信息,说明已经连接上了,而且这个smtp服务器是postfix做的。

  “MAIL FROM: teste@dominio.com.br”这个命令指明了发件地址是teste@dominio.com.br,“250 Ok”说明这条命令被服务器接受并正确执行,这类似http协议的200、404、500等状态代码。接下来的“RCPT TO: teste@dominio.com.br”指明了收件地址是teste@dominio.com.br。

  引用:

DATA
354 End data with .
teste
.

  这一段是输入邮件正文,输入“DATA”以后系统提示使用“.”来结束输入,正文内容是“teste”。

  最后使用“QUIT”退出。

  注:以上来自netkiller的postfix文档,偷懒,直接用现成的。

  首先是使用telnet来连接本地的25端口,稍微熟悉点网络的人都知道smtp协议使用25端口,这也就是说,现在在连接本地的smtp服务器。

  引用:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server.domain.com.br ESMTP Postfix (2.1.0)

  这些东西是系统输出信息,说明已经连接上了,而且这个smtp服务器是postfix做的。

  “MAIL FROM: teste@dominio.com.br”这个命令指明了发件地址是teste@dominio.com.br,“250 Ok”说明这条命令被服务器接受并正确执行,这类似http协议的200、404、500等状态代码。接下来的“RCPT TO: teste@dominio.com.br”指明了收件地址是teste@dominio.com.br。

  引用:

DATA
354 End data with .
teste
.

  这一段是输入邮件正文,输入“DATA”以后系统提示使用“.”来结束输入,正文内容是“teste”。

  最后使用“QUIT”退出。

 

  注:以上来自netkiller的postfix文档,偷懒,直接用现成的。

  首先是使用telnet来连接本地的25端口,稍微熟悉点网络的人都知道smtp协议使用25端口,这也就是说,现在在连接本地的smtp服务器。

  引用:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server.domain.com.br ESMTP Postfix (2.1.0)

  这些东西是系统输出信息,说明已经连接上了,而且这个smtp服务器是postfix做的。

  “MAIL FROM: teste@dominio.com.br”这个命令指明了发件地址是teste@dominio.com.br,“250 Ok”说明这条命令被服务器接受并正确执行,这类似http协议的200、404、500等状态代码。接下来的“RCPT TO: teste@dominio.com.br”指明了收件地址是teste@dominio.com.br。

  引用:

DATA
354 End data with .
teste
.

  这一段是输入邮件正文,输入“DATA”以后系统提示使用“.”来结束输入,正文内容是“teste”。

  最后使用“QUIT”退出。

共2页: 上一页 1 [2] 下一页



Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!