Recently, when i was working on one of my hobby projects, i faced some problems about sending mail from localhost.
I tried to send mail using PHP’s mail function. It seems very simple at first look, but when i got following error message,
SMTP Error 550, unknown command.
i got frustrated. After a while I searched this problem and i found some security issues about SMTP protocol. Because of these security issues, sending mail is not easy as it looks.
First, this SMTP error message is related to SMTP server existence. I didn’t have an SMTP server when i got this error message. This means if you are working on a local computer, you must use a mail server. Mercury is a mail server you can use. After installing Mercury, you must configure php.ini. The following part of this file is changed.
; For Win32 only.
SMTP = localhost
smtp_port = 25 -> this is the port that mail server listens.
; For Win32 only.
;sendmail_from = email@example.com
sendmail_from = postmaster@localhost -> postmaster is admin of mercury mail server.
After configuring the file as stated above, when you try to send your email as xxx@localhost, public SMTP servers(smtp.live.com, smtp.gmail.com) will probably ignore since it may be spam.
Following article at pcmag.com explains spam issue.
Use TCP Port 587 For Mail Submission
The quote below is from this article:
The conventional way for a mail client program to send e-mail is using TCP port 25, which is also the port used by mail servers to talk to each other. But port 25 is widely abused by malware to spread worms and spam. As a result, many ISPs are restricting its use.
Most users shouldn’t have a problem anyway. If you only send mail using their ISP account, you can probably still send it using the ISP mail server. But if you want to send mail using the mail server for your office, or perhaps a hosted mail server for a domain you own, you could have problems.
After installing mercury, it must be configured to be a Relay SMTP server instead of real SMTP server.
This article at the link below explains why it must be configured as “Relay”.
Apache Friends Support Forum
This quotation is from that article:
The PHP mail()-function supplys only a very simple API in order to send mail via SMTP servers that do *not* require any authorization. Unfortunately, all public SMTP servers (like smtp.gmail.com etc.) require authorization, therefore you *cannot* send mails directly via mail() using these public servers.
If you supply “localhost” as SMTP server, you must (of course) install a local SMTP server, for example Mercury. For the same reason, you must not configure it using any authorization. Mercury comes in several flavours, one of them is a real SMTP server, but usually most mail boxes block mails coming from privat IPs (like yours), these IPs are blacklisted due to SPAM reasons. Therefore it is not usefull to run Mercury as a real SMTP server. Instead, you may install Mercury as a “Relay SMTP” client, which simply relays all mails to a public SMTP server (like smtp.gmail.com).
If we want to set Gmail as out Relay SMTP client, we must know Gmail’s E-mail client configuration. It is explained at this link. Then we must configure Mercury SMTP relay client settings according to this configuration.
The article at http://www.danieltmurphy.com/setting-up-mercury-smtp/ explains this configuration. I would like to thank for this detailed explanation.