Solved PHP can't send email

vyalmicro

New Member

Reaction score: 2
Messages: 10

I have installed FreeBSD 10 x86_64 on my new server (BEMP- BSD, nGinx, MySQL, PHP). I am using php55 and php55-extensions. I have also installed php55-imap. Still PHP is unable to send email. I don't want to receive emails, I just need PHP applications to send them.
 

AndyUKG

Well-Known Member

Reaction score: 22
Messages: 456

Normally PHP can send mail if you can send mail from the command line. Does the following send mail:

echo "test content" | mailx -s "test subject" your@email.com

If not you need to check your mail logs and work out why this isn't working.
 
OP
OP
vyalmicro

vyalmicro

New Member

Reaction score: 2
Messages: 10

Normally PHP can send mail if you can send mail from the command line. Does the following send mail:

echo "test content" | mailx -s "test subject" your@email.com

If not you need to check your mail logs and work out why this isn't working.
Failed once again :(

Code:
Oct 20 09:11:32 freebsd-8353 sendmail[16679]: s9K9BV5b016679: to=vyal.micro@gmail.com, ctladdr=www (80/80), delay=00:00:01, xdelay=00:00:01, ma$
Oct 20 09:12:08 freebsd-8353 sm-mta[16661]: s9K95rhV016659: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:0$
Oct 20 09:17:47 freebsd-8353 sm-mta[16682]: s9K9BVCG016680: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:0$
Oct 20 09:26:23 freebsd-8353 sm-mta[16690]: s9K9BVCG016680: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:1$
Oct 20 09:26:23 freebsd-8353 sm-mta[16690]: s9K95rhV016659: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:2$
Oct 20 09:26:23 freebsd-8353 sm-mta[16690]: s9K92gLw014872: to=<sanatantech@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:$
Oct 20 09:26:23 freebsd-8353 sm-mta[16690]: s9K8k0MA069590: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:4$
Oct 20 09:56:23 freebsd-8353 sm-mta[16751]: s9K9BVCG016680: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:4$
Oct 20 09:56:23 freebsd-8353 sm-mta[16751]: s9K95rhV016659: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:5$
Oct 20 09:56:23 freebsd-8353 sm-mta[16751]: s9K92gLw014872: to=<sanatantech@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=00:$
Oct 20 09:56:23 freebsd-8353 sm-mta[16751]: s9K8k0MA069590: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=01:1$
Oct 20 10:26:23 freebsd-8353 sm-mta[16808]: s9K9BVCG016680: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=01:1$
Oct 20 10:26:23 freebsd-8353 sm-mta[16808]: s9K95rhV016659: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=01:2$
Oct 20 10:26:23 freebsd-8353 sm-mta[16808]: s9K92gLw014872: to=<sanatantech@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=01:$
Oct 20 10:26:23 freebsd-8353 sm-mta[16808]: s9K8k0MA069590: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=01:4$
Oct 20 10:56:23 freebsd-8353 sm-mta[16870]: s9K9BVCG016680: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=01:4$
Oct 20 10:56:23 freebsd-8353 sm-mta[16870]: s9K95rhV016659: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=01:5$
Oct 20 10:56:23 freebsd-8353 sm-mta[16870]: s9K92gLw014872: to=<sanatantech@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=01:$
Oct 20 10:56:23 freebsd-8353 sm-mta[16870]: s9K8k0MA069590: to=<vyal.micro@gmail.com>, ctladdr=<www@localhost.freebsd-8353> (80/80), delay=02:1$
Oct 20 11:01:59 freebsd-8353 sendmail[16910]: s9KB1xNq016910: from=root, size=61, class=0, nrcpts=1, msgid=<201410201101.s9KB1xNq016910@localho$
Oct 20 11:01:59 freebsd-8353 sendmail[16910]: STARTTLS=client, relay=[127.0.0.1], version=TLSv1/SSLv3, verify=FAIL, cipher=DHE-RSA-AES256-GCM-S$
Oct 20 11:01:59 freebsd-8353 sm-mta[16911]: STARTTLS=server, relay=localhost [127.0.0.1], version=TLSv1/SSLv3, verify=NO, cipher=DHE-RSA-AES256$
Oct 20 11:01:59 freebsd-8353 sm-mta[16911]: s9KB1xG4016911: from=<root@localhost.freebsd-8353>, size=390, class=0, nrcpts=1, msgid=<20141020110$
Oct 20 11:01:59 freebsd-8353 sendmail[16910]: s9KB1xNq016910: to=vyal.micro@gmail.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mai$
This is from /var/log/maillog. How to understand this?
 

AndyUKG

Well-Known Member

Reaction score: 22
Messages: 456

Is DNS working on your server? I.e. can you do dig -t mx gmail.com? If not configure /etc/resolv.conf. If yes can you verify sendmail can send with the command sendmail -bv your@email.com?

Also you are likely to run into problems emailing Gmail with an unrouteable email address such as "www@localhost.freebsd-8353". Try setting sendmail_from in your php.ini file to a real email address.

Thanks, Andy.
 
OP
OP
vyalmicro

vyalmicro

New Member

Reaction score: 2
Messages: 10

Hello Andy,

Yes DNS is perfectly working on my server:
Code:
root@freebsd-8353:/usr/local/www/vyal #  dig -t mx gmail.com

; <<>> DiG 9.10.1 <<>> -t mx gmail.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42530
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;gmail.com.       IN   MX

;; ANSWER SECTION:
gmail.com.     2297   IN   MX   10 alt1.gmail-smtp-in.l.google.com.
gmail.com.     2297   IN   MX   5 gmail-smtp-in.l.google.com.
gmail.com.     2297   IN   MX   20 alt2.gmail-smtp-in.l.google.com.
gmail.com.     2297   IN   MX   30 alt3.gmail-smtp-in.l.google.com.
gmail.com.     2297   IN   MX   40 alt4.gmail-smtp-in.l.google.com.

;; Query time: 15 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Mon Oct 20 11:54:02 UTC 2014
;; MSG SIZE  rcvd: 161
Sendmail test gives:
Code:
root@freebsd-8353:/usr/local/www/vyal # sendmail -bv sanatantech@gmail.com
sanatantech@gmail.com... deliverable: mailer esmtp, host gmail.com., user sanatantech@gmail.com
I had no php.ini, /usr/local/etc/ had php.ini-development and php.ini-production. I am using production version (correct choice, right?) by renaming it to php.ini
Now setting sendmail_from to vyal.micro@gmail.com to see if it works.
 
OP
OP
vyalmicro

vyalmicro

New Member

Reaction score: 2
Messages: 10

Nope, it still fails :(

EDIT:

Should I install postfix and configure it instead?
 

AndyUKG

Well-Known Member

Reaction score: 22
Messages: 456

Hi, there's no reason it shouldn't work with sendmail but you are free to test whatever you want. I'm personally more used to mail/exim.

Oh, I forgot something quite important before, if you are sending from an IP with no reverse DNS record (PTR) your emails may well be rejected due to that.

What is now in your mail logs?
 
OP
OP
vyalmicro

vyalmicro

New Member

Reaction score: 2
Messages: 10

Hello,
I tried to verify if I have working reverse DNS at http://www.digwebinterface.com
It gave me following result:
Code:
<IP ADDRESS>@8.8.4.4 (Default):
<IP ADDRESS>.in-addr.arpa. 1763 IN   PTR   <IP ADDRESS>.vultr.com.
Does it means reverse DNS is working?

EDIT:
I deleted the old log file. I tried to send emails from Wordpress and the terminal once again but no new logs were created.
 

AndyUKG

Well-Known Member

Reaction score: 22
Messages: 456

Does it means reverse dns is working?

EDIT:
I deleted the old log file. I tried to send emails from wordpress and terminal once again but no new logs were created....
Yes you have a PTR record in DNS.

Something is wrong if you get no logs, what about trying sending via mailx as per my first reply?
 

ShelLuser

Son of Beastie

Reaction score: 1,671
Messages: 3,512

First of all; yes, it would appear as if your reverse DNS is working as expected. However, I'd also like to advise you to be careful with sharing your IP address on a public forum.

Having that out of the way; I wonder if a firewall (or a local ISP) isn't simply blocking the outgoing port 25. This is a very common approach when ISP's want to prevent clients from running their own MTA and instead provide them with a smarthost.

Easy way to try is to deliver e-mail manually. You tried gmail.com, so basically: $ telnet gmail-smtp-in.l.google.com 25.

Does that do anything for you?
 
OP
OP
vyalmicro

vyalmicro

New Member

Reaction score: 2
Messages: 10

Okay, logs and all are working. it looks like Vultr blocks outbound emails until further verification. Ah... I'll try to get it verified, if that doesn't work then probably the only way left would be to use something like Sendgrid.

And yes, I shouldn't have written my real IP, nice reminder ShelLuser, removing it.
 
Top