Problem sending email on form submission in WordPress

Adding a form to your WordPress website is normally done by using a plugin for it, like Contact Form 7 for example. At some hosting providers, there can be a problem for the plugin to send emails to you when someone is posting through the form. To prevent spam through forms, many hosting providers disable the PHP mail function that is used in WordPress to send emails, causing for example form plugins not being able to send emails.

The solution is to set up WordPress to use SMTP, preferrably with authentication, to send the emails through a real email server. To do this you need a plugin like WP Mail SMTP. Set it up either with the hosting provider’s SMTP server or use the one you normally use for email.

PHP Parse error: syntax error, unexpected end of file in XXXXX.php

  • Check that you have spaces around curly braces, i.e. for example don’t use <?php}?> but instead use <?php } ?>
  • If your script has been running without problems on earlier versions of PHP but you are now running PHP 5.4 or later, replace all occurrences of <? with <?php