0

I have a form on my website and i'd like it to send me an email when they submit the form. Do I have to set up an SMTP server or can I send it just with a PHP script? Thanks

Bjj6
  • 11

1 Answers1

0

You have the following options:

  • you could send mail directly to the recipient's server (MX), without going through an SMTP server. The issue with this is that if the destination server is unavailable at that time (maintenance, disk full, outage...), the e-mail will be lost. This will also not work with destinations that use grey listing. And it adds a lot of complexity for handling multiple MX (destination) servers, signatures, SPF, etc.

  • you could use an existing SMTP server. Depending on the server you use, you might need to authenticate, and there may be restrictions on sender, number of recipients, number of e-mails you can send, etc.

  • you can set up you own SMTP server, such as sendmail, or postfix. This adds a bit of admin overhead, and you may have issues with the reputation of your server (and thus deliverability) if you don't do things properly.

jcaron
  • 17,302
  • 6
  • 32
  • 46
  • 2
    i would love to know how you think the first option works. –  Sep 27 '16 at 21:05
  • @nogad In my experience the first option is the worst. 99% percent of the time, the email is marked as SPAM. Because came from a non trusty source. – manuerumx Sep 27 '16 at 21:08
  • You're wrong. The first option requires your server to be configured with one of the other two. – catbadger Sep 27 '16 at 21:08
  • You seem to think it's not possible to send e-mail directly from a PHP script without going though an SMTP server (not counting the destination server, of course)? Not saying this would be efficient or reliable in any way, but it's very obviously possible. Look up MX. Open port 25 to said MX. EHLO, MAIL FROM, RCPT TO, DATA. What do you think an SMTP server does? – jcaron Sep 27 '16 at 21:11
  • that IS a mail-server listening on port 25 –  Sep 27 '16 at 21:12
  • No, I'm talking about a client connecting to port 25 on a remote host. – jcaron Sep 27 '16 at 21:16
  • I'm lost as to your thought process; but really, no mail server, no mail. So the first point is just wrong. –  Sep 27 '16 at 21:18
  • I'm lost as to yours. What's your issue with an SMTP client? By definition, if there's a server (the destination MX), there's a client. It does not need to be a server (though it's much better if it is). – jcaron Sep 27 '16 at 21:20
  • "you could send mail directly to the recipient, without going through an SMTP server. " no you can't. full stop end of story –  Sep 27 '16 at 21:21
  • Ah, OK, got your issue. Edited answer to specify I meant the recipient's server (MX), which will receive and deliver the mail. As opposed to your own/your ISP's/your webhost's SMTP server (relay) that will store and forward the e-mail, which is what the other two (more traditional) options are about. – jcaron Sep 27 '16 at 21:25
  • That's the first time ever i have seen some one purpose looking up the the mx record and sending directly. Have you ever done that in php? –  Sep 27 '16 at 21:31
  • Not in PHP but I doubt it would be an issue. Though, once again, it is definitely not a route I would recommend. It's just something you **could** do. – jcaron Sep 27 '16 at 21:59
  • You could even use `mailto:youraddress@....` as the action of the form. If the visitor has their mail client setup propertly, the form data will be mailed from them to you. Unreliable method, though, but in the early years this was used quite a lot, and you don't need any server side scripting for it. See [this question](http://stackoverflow.com/questions/12626940/mailto-on-submit-button). – GolezTrol Sep 28 '16 at 06:13
  • Do I understand from all of the above conversation that PHP does not natively talk to a destination SMTP server? Why then are there the `SMTP` and `smtp_port` lines in `php.ini`? – Sam Sirry Jun 18 '17 at 08:32