Question

PHP Contact Form

I have a static index.html running on a nginx server. I have a simple form element that takes in a user’s contact details and sends a POST request to inc/sendEmail.php. I haven’t set up any mail system on my droplet so maybe that’s why it’s not sending any email? Everything code wise looks pretty solid but I’m not sure where to start to get my code to start working for me. I’m running Ubuntu 18.04 and NGINX. When I hit submit I get a ‘200 OK’ response from jquery sending the post to the PHP script but that’s as far as it goes and then it throws my error something went wrong. Any advice is appreciated.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Greetings!

Thank you for posting this question here. To wrap up this post with a dedicated answer, it seems that you were able to resolve this by comparing the script at this URL to your code:

https://www.arclab.com/en/kb/php/how-to-test-and-fix-php-mail-function.html

That is a good reference, for anyone experiencing similar. However, it is also worth noting that there are a lot of complexities to sending email that did not exist several years ago. For that reason, one should also check their MTA logs to see if they can find out what happened when they sent an email. For example, if I’m sending an email to “jarland@gmail.com” and using Postfix on the droplet, I might run this to check the logs:

grep "jarland@gmail.com" /var/log/mail.log

Some more information on debugging Postfix logs (as it is the most common MTA, to the best of my knowledge):

https://easyengine.io/tutorials/mail/postfix-debugging

Jarland