Blog thread for backend issues!
Welcome to Server Side Sundays, a blog thread focused on solutions to issues that arise while developing backend applications and/or tips for server side projects.
For our first blog, let’s talk about developing your our own PHP contact forms. The issue that we are going to be covering is an authentication failure [SMTP: Invalid response code received from server (code: 534, response: 5.7.14)] while setting up a SMTP (Simple Mail Transfer Protocol) using PEAR mail package.
At first, we were using PHP’s function mail(). However, this function sends an email directly from the web server that your site is being hosted on. Depending on where the email is going, it might be be blocked if the server ip your site is hosted on has been blacklisted or you change the ‘From’ tag within the headers. For gmail, you won’t run into any problems but if a recipient uses outlook (hotmail, live, etc.) it will be blocked, which is what we saw.
First things first, you need a form within your html file. This should include a name, email address, phone number, subject and question or message.
Here is the codepen link for a simple and unstyled form contact form. It is important to include some sort of antispam field. We did this by hidding an input that a bot would alter. In the contact form, we check for this.
Next, the fun stuff. So in order for our form to do anything. We have to include a php file entitled contactForm.php in the same directory as the html. By assigning an action to the form (action=“contactForm.php”) we are affectively going to post to that file.
To set up the mailing function you have two steps:
Finally, you have to allow access to your gmail account. If not, you will get the authentication failure [SMTP: Invalid response code received from server (code: 534, response: 5.7.14)] .
There you go, you should at this point have a fully functioning contact form! Let us know if there are any topics that you would like covered or question you have.