1

I have a small Ubuntu 16.04 VPS that's running nginx/php-fpm to run a Wordpress site, and running an SMTP server through Postfix/Saslauthd. My mail server is working just fine at sending and receiving mail, and I have Wordpress set up to use SMTP instead of php mail() through the Postman plugin and that works perfectly.

However, when attempting to submit an email contact form through Wordpress, I keep getting a 405 Not Allowed error. I tried a couple different contact form plugins (Pirate Forms, Contact Email Form) and still got the same result. I also disabled Postman to force Wordpress to use php mail(), but still got a 405.

Nginx debug logs here Nginx config here.

EDIT: URL I'm trying to post to is https://example.com/contact/

Nginx access log shows this:

xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:07 -0400] "GET /favicon.ico HTTP/2.0" 200 524 "https://example.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"
xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:08 -0400] "GET /contact/ HTTP/2.0" 200 6090 "https://example.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"
xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:09 -0400] "GET /favicon.ico HTTP/2.0" 200 524 "https://example.com/contact/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"
xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:22 -0400] "POST /contact/ HTTP/2.0" 405 626 "https://example.com/contact/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"
xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:22 -0400] "GET /favicon.ico HTTP/2.0" 200 524 "https://example.com/contact/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"

Not getting anything in error.log.

  • HTTP 405 is "method not allowed", so most likely you're trying to POST to a URL that doesn't accept POST. Please post Nginx access and error logs, and tell us the URL you're trying to post to. Browser should post to PHP, which then uses the mail function to send email. You need to flesh out your question and remove extraneous information - the last four paragraphs are irrelevant. – Tim Oct 9 '16 at 23:32
  • Edited per your recommendations. – 4oo4 Oct 10 '16 at 0:16
  • That's much more concise, first link now invalid. The problem is the code behind the /contact/ URL, which isn't accepting the POST request. You haven't provided enough information to figure that out - PHP access and error logs would probably be a good place to look. You'll have to do diagnostics. – Tim Oct 10 '16 at 0:19
  • Fixed the link. I was tailing php7.0-fpm.log while I was trying the POST and it wasn't outputting anything. Is there something in php.ini or php-fpm.conf that I need to set to get better logging output? I was wondering if the fastcgi_intercept_errors in my nginx config might also affect that. – 4oo4 Oct 10 '16 at 0:33
0

You're getting the 405 error because you are passing all requests first to memcached, but it can only handle GET (and HEAD) requests. This upstream therefore returns 405 Method Not Allowed. You need to actually handle this, but at the moment you are ignoring it. I think the easiest way to do it would be to add 405 to the list of errors you handle in error_page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.