can php send email without mail server installed in server?

痞子三分冷 提交于 2019-12-24 02:59:15

问题


I know we can send email from php using smtp servers on different hosts or if there is local smtp server installed. What I want to know is can php send email without any local or remote smtp servers? I have heard about sendmail program but can it function without any mail server installed in the server?


回答1:


At some point you have to talk to a SMTP server. Sending via a SMTP server on the local host is the cleanest option and the most likely to succeed at getting through spam filters.

What a mail server does is quite complex. Let's take your average e-mail as it arrives from your e-mail client to your e-mail server with an outbound host as the destination:

  1. The server checks your user account and makes sure it is valid.
  2. The e-mail goes into a queue either separately for each recipient or as one message (depends on the server).
  3. The server finds the e-mail in the queue and processes each recipient address. This requires a DNS lookup for a MX record for each target domain.
  4. The e-mail server connects to the address specified by the MX record and delivers the e-mail to it as one does over SMTP.
  5. On success, the e-mail is removed from the queue. On failure, the e-mail may remain in the queue and the server will try again later (exponential backoff - see greylisting) or be put in the mail queue to be returned to you when you check your e-mail via POP3 later.

The next e-mail server in the queue then repeats the above until the final server receives the e-mail and sits in the recipient's mailbox.

Doing that within PHP is possible, but I don't recommend it. MX record lookup can be tricky because people do all sorts of non-compliant things that mail servers tolerate. Plus, your script might time out while attempting to connect directly to the target SMTP server. Some servers are also configured to "greylist" e-mail, which means the e-mail will initially be rejected but would be accepted later (e.g. 30 minutes is not unusual). The average PHP script won't be able to handle that scenario.



来源:https://stackoverflow.com/questions/14208817/can-php-send-email-without-mail-server-installed-in-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!