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.


@dawnsky Thank you. I managed to fix it by first using the script you supplied me and testing to verify the mail function was working. Upon realizing the mail() function was working I made an adjustment to my PHP script which fixed the issue. Thank you for your help.

Please visit the following link to get a test script for the email function–

This will let you know if your SMTP relay portion is working. You will have to check the receiving mailbox for the resulting message.

@dawnsky First of all thank you for your research, time, and thorough comment. I have the <?php tag which seems fine, the form action is linking to the folder with the php script in it. Would you mind sharing the php script you used to test and the steps you took? Thanks.

Resolved for me.

There was a tag ‘<?’ but should have been ‘<?php’ in the code. After I made the change, my form rendered correctly and tested fine.

After looking at your post a second time, do you have any PHP code in the HTML file? If so, does it need to have the .php not .html?

My form uses the PHP mail() command to send.

I wanted to know if it was the mail app being used on the droplet, a DNS issue, or PHP.

Validated PHP as per the DO tutorial.

Initially had some DNS issues, but resolved them.

Found a PHP script that tests the SMTP relay at the server side. All tests worked, but the messages went to SPAM, so a side mystery.

So what else could it be? During my research I came across a thread where one of the posts said to check for the deprecated <? tag. He explained that the mixture of <?php and <? tags would cause issues. And there you have it.

I am running an Ubuntu-Nginx-LEMP droplet, latest updates, PHP 7.2. Left everything at defaults. Did not edit any files. Did not touch any mail clients, so using the default send only stack. Running UFW, firewall allows 22, 80 and 443 inbound. Using /var/www/html the default Nginx server block.

Got lucky on this one. Hope this is helpful for you. Cheers and rock on!

@dawnsky Thank you very much I appreciate your involvement and your time.

@mikem255 I have the same requirement. Have done extensive reading on this and found various solutions. Going to try the easiest first, then report back soon.

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

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.


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:

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 “” and using Postfix on the droplet, I might run this to check the logs:

grep "" /var/log/mail.log

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