I’m trying to get a contact form working on our WordPress site, and it is a little more complicated than I thought it might be.
The contact form plugin itself in WordPress. We’re using Contact Form 7. Documentation for Contact Form 7 says something to the effect “we’re sending upteen zillion eMails a day, and CF form “just works” for everybody. Well, kinda, sorta. There are several other issues involved:
- an MTA (mail transfer agent) which maybe (?) has to be on the WordPress server
- the php_mail() function which is part of PHP (the programming language for WordPress)
- the wp_mail() function which may or may not call the php_mail() function
- Restrictions on to and from addresses.
I wanted to just run everything through our Google Mail SMTP account, but that seems to add an additional layer. So first I started with our blog site which is on another server, and tested whether the contact form worked there. It actually doesn’t, that is, it appears to send mail correctly from the users’s perspective, but no email was received anywhere.
Per this note I checked to see if anything was listening on port 25, the usual SMTP port.
$ netstat -tanpl | grep :25 tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3030/master tcp6 0 0 ::1:25 :::* LISTEN 3030/master $ lsof -i :25 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME master 3030 root 12u IPv4 9667 0t0 TCP localhost:smtp (LISTEN) master 3030 root 13u IPv6 9668 0t0 TCP ip6-localhost:smtp (LISTEN)
Looks promising. it appears that both IP4 and IP6 are listening.
So, I created a basic PHP script to test at the server command line, and saved this as testphpmail.php. There are three parameters, the receiver’s address, the subject and the body of the message.
//This is a test of the basic PHP eMail function. <?php mail('firstname.lastname@example.org', "Test PHP Mail", "Test mail from PHP Mail"); ?>
Run this script from the command line with the following command:
php -f testmail.php
This worked; I received the eMail. It shows that it comes from root. At least I knew that at least the fundamentals are in place on the server.
Checking the mail log, at /var/log/mail.log I see the following:
$ cat/var/log/mail.log May 20 14:28:17 li239-124 postfix/pickup: 11864F123: uid=0 from=<root> May 20 14:28:17 li239-124 postfix/cleanup: 11864F123: message-id=<20160520142817.11864F123@localhost> May 20 14:28:17 li239-124 postfix/qmgr: 11864F123: from=<root@localhost>, size=351, nrcpt=1 (queue active) May 20 14:28:17 li239-124 postfix/smtp: 11864F123: to=<email@example.com>, relay=aspmx.l.google.com[126.96.36.199]:25, delay=0.21, delays=0.01/0.01/0.1/0.09, dsn=2.0.0, status=sent (250 2.0.0 OK 1463754497 e92si18328547qga.115 - gsmtp)
So this shows that the message was sent, using root@localhost as the sender’s address and my work eMail as the target. And indeed, I received this email at work.
I checked the log file at /var/log/mail.log which presented various points of interest…including the fact that we are running the Postfix sendmail email server. But there is also a status=bounced message for IP6.
$ cat /var/log/mail.log May 20 13:50:15 li239-124 postfix/pickup: 2973DF23B: uid=33 from=<www-data> May 20 13:50:15 li239-124 postfix/cleanup: 2973DF23B: message-id=<firstname.lastname@example.org> May 20 13:50:15 li239-124 postfix/qmgr: 2973DF23B: from=<www-data@localhost>, size=869, nrcpt=1 (queue active) May 20 13:50:15 li239-124 postfix/smtp: 2973DF23B: to=<email@example.com>, relay=aspmx.l.google.com[2607:f8b0:400d:c08::1a]:25, delay=0.41, delays=0.01/0.01/0.09/0.3, dsn=5.7.1, status=bounced (host aspmx.l.google.com[2607:f8b0:400d:c08::1a] said: 550-5.7.1 [2600:3c03::f03c:91ff:fe6e:916c] Our system has detected that this 550-5.7.1 message does not meet IPv6 sending guidelines regarding PTR records 550-5.7.1 and authentication. Please review 550-5.7.1 https://support.google.com/mail/?p=ipv6_authentication_error for more 550 5.7.1 information. a139si18154032qkc.140 - gsmtp (in reply to end of DATA command)) May 20 13:50:15 li239-124 postfix/cleanup: 8DAAAF23C: message-id=<20160520135015.8DAAAF23C@localhost> May 20 13:50:15 li239-124 postfix/bounce: 2973DF23B: sender non-delivery notification: 8DAAAF23C May 20 13:50:15 li239-124 postfix/qmgr: 8DAAAF23C: from=<>, size=3381, nrcpt=1 (queue active) May 20 13:50:15 li239-124 postfix/qmgr: 2973DF23B: removed May 20 13:50:15 li239-124 postfix/local: 8DAAAF23C: to=<www-data@localhost>, relay=local, delay=0.01, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox) May 20 13:50:15 li239-124 postfix/qmgr: 8DAAAF23C: removed root@li239-124:~# dpkg -S 'which sendmail' dpkg-query: no path found matching pattern *which sendmail*. root@li239-124:~# netstat -tanpl | grep:25 grep:25: command not found root@li239-124:~# netstat -tanpl | grep :25 tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3030/master tcp6 0 0 ::1:25 :::* LISTEN 3030/master
Just to be sure, I ran the PHP script again having it send to my home email address which is outside my work domain. This bounced and I didn’t receive it at the home address. Now, in theory, this might not be a bad thing, since all of the Contact Form 7 messages from the blog page should be sent to an address within the same domain, like firstname.lastname@example.org.
So far, then we’ve established:
- PostFix is installed on the blog’s server.
- Contact Form 7 shows that it is sending message, but the messages are bouncing. (Hmm…I wonder what I’ve been missing all those times? )
This is so typical of IT. You think you’re troubleshooting an issue on one server, and upon investigating the same issue on another server that you think is working…you find that it isn’t and down the rabbit hole you go!