Ajax & PHP Contact Form

Ajax & PHP Contact Form

Developed by HTML Codex

Version 2.0.0

Introduction

We appreciate your purchase of our premium Ajax & PHP Contact Form. Our form enables you to send mails effortlessly using both the PHP mail() function and the SMTP system. It's designed for easy installation and seamlessly integrates with all templates from HTML Codex. This manual provides a straightforward guide to install the Contact Form and make it fully functional. We've taken great care to simplify the instructions, ensuring a clear and user-friendly experience.
Features
Requirements

This Contact Form requires at last PHP version 5.5 in your hosting server. Your hosting should allow you to send emails with using the PHP mail() function. You can use SMTP method if the mail() function is not supported.

Live Demo

File Structure

The ZIP file contains HTML, JavaScript, and PHP files. After extracting the ZIP file you'll see the following files & folders structure.

                
                    docs.html
                    form.html
                    mailer/
                    ├── contact.form.js
                    ├── contact.form.php
                    ├── validation.form.js
                    ├── PHPMailer/
                    |   ├── PHPMailer.php
                    |   ├── Exception.php
                    |   ├── SMTP.php
                    |   ├── and more...
                
            

Setting Up

The Contact Form is very easy to install and works with all templates designed by HTML Codex. Please follow the below instructions step by step.

1. Extract the "contact-form.zip" file. You will see the following files & folders structure.

                
                    docs.html
                    form.html
                    mailer/
                    ├── contact.form.js
                    ├── contact.form.php
                    ├── validation.form.js
                    ├── PHPMailer/
                    |   ├── PHPMailer.php
                    |   ├── Exception.php
                    |   ├── SMTP.php
                    |   ├── and more...
                
            

2. Keep the "mailer" folder in the root directory. After placing the "mailer" folder in the root directory the structure will look like the example below.

                
                    template/
                    ├── css/
                    ├── img/
                    ├── js/
                    ├── lib/
                    ├── mailer/
                    ├── index.html
                    ├── contact.html
                    ├── and more HTML files...
                
            

3. Copy the below HTML code for the contact form and paste it to your contact page where you want it.

                
            
4. Copy the JS files links code below and paste it into the footer area of your contact page (before the closing body tag).

                
                    <!-- Contact Form Javascript -->
                    <script src="mailer/validation.form.js"></script>
                    <script src="mailer/contact.form.js"></script>
                
            

5. Copy the CSS code below and paste it into the header area of your contact page (before the closing head tag). Don't forget to save the file after making the changes.

                
                    <style type="text/css">
                        #contactForm .help-block ul {
                            margin: 0;
                            padding: 0;
                            list-style-type: none;
                        }
                    </style>
                
            

Activation

Your Contact Form is now fully installed. Now you need to activate it to make it work. Follow the instructions below step by step.

1. Open the "contact.form.php" file from the "mailer" folder.

2. Change the recipient name and email address and save the file.

                
                    // Recipient name. Change this name to your
                    $recipientName = "Joe User";

                    // Recipient email. Change this email to your
                    $recipientEmail = "joe@example.com";
                
            
Now your Contact Form is ready. Upload the template to the web host and test it. You should receive the test message in your email shortly.

SMTP Settings

The Contact Form utilizes the PHP mail() function as its default mailing method. However, it also includes a configuration for SMTP in case your hosting doesn't support the PHP mail() function for sending emails. If your hosting doesn't support the PHP mail() or you prefer to use the SMTP system, you'll need to enable it and add your SMTP credentials. Please follow the instructions below for guidance.

1. Open the "contact.form.php" file. Look for the word "useSMTP" and remove the word "false," then type in "true" instead.

                
                    // Set mailer to use SMTP or PHP's mail() function
                    // If you use SMTP, it will be "true". Otherwise, it will be "false"
                    $useSMTP = true;
                
            

2. You need to provide the following SMTP-related information. Don't forget to save the file after making the changes.

            
                // Server settings for SMTP
                $mail->isSMTP();
                $mail->Host = 'smtp.example.com';
                $mail->SMTPAuth = true;
                $mail->Username = 'user@example.com';
                $mail->Password = 'secret';
                $mail->SMTPSecure = 'tls';
                $mail->Port = 587;
            
        

Mobile Number Settings

By default, the mobile number field is enabled. If you prefer not to use the mobile field, you can simply remove it.

1. Open the "contact.html" file and remove the HTML code for mobile number field mentioned below.

                
            

2. Don't forget to change the CSS class for the subject field from "col-sm-6" to "col-12". See the below example.

                
            

Error Messages

To customize the error messages, it's easy to do so. Just open your "contact.html" file, locate the "data-validation-required-message", and customize the error messages as desired.

                
            

Troubleshooting

Although the Contact Form is 100% error-free, it may not work in some cases. If you face any problems while using it, please find your solution in the FAQ below. Please contact us if no solution is found. Our team will try to solve your problem within a short time.

First, make sure that your Contact Form is set up correctly and that all the required fields are filled out. Next, check your email settings to make sure that you are using the correct recipient name and email address. If you use SMTP method then check the SMTP settings are correctly configured.

If your server does not support the PHP mail() function, you still have an alternative option to enable email functionality on your website. You can use the SMTP method easily. Please see the instruction here on how to configure the SMTP system.

Even if your server supports the mail() function, there may be some reasons why the email is not being sent.

  • Make sure that your Contact Form is set up correctly.
  • Check your email settings to make sure that you are using the correct recipient name and email address.
  • Some hosting providers don't allow external recipients when using PHP mail().
  • Please change the recipient email address to an email address from the server's domain. For example, if your server domain is "www.yourdomain.com", then the recipient's email should be "someone@yourdomain.com".
  • Please test the Contact Form with the same email as used for the recipient if not working.
  • If it's still not working, you should use the SMTP method. Please see the instruction here on how to configure the SMTP system.

There are a few potential reasons.

  • Ensure that your server supports the mail() function or that SMTP settings are correctly configured.
  • Double-check your SMTP configuration (server, port, username, password, encryption) and verify that the email addresses are valid.
  • Check your spam folder in case emails are getting flagged as spam by your email provider.
  • Firewall or Antivirus Blocking: In some cases, firewalls or antivirus software might be blocking the outgoing emails. Verify if there are any security programs causing interference and adjust their settings if needed.
  • IP Address Blocking: If there were previous unethical behaviors from the IP address, the server might have temporarily blocked the IP for security reasons. In this case, waiting for a while and trying again might resolve the issue.

The error message "SMTP Error: Could not authenticate" indicates that there was a problem with the authentication process while attempting to send an email through the Simple Mail Transfer Protocol (SMTP). There are a few possible reasons for this issue:

  • Incorrect Username or Password: The most common reason for this error is that the username and/or password used for authentication are incorrect. Double-check the login credentials you are using to ensure they are accurate.
  • Authentication Method: SMTP servers often support different authentication methods, such as plain text, encrypted (SSL/TLS), or secure methods like OAuth. Ensure that you are using the correct authentication method as required by the SMTP server you are connecting to.
  • Firewall or Antivirus Blocking: In some cases, firewalls or antivirus software might be blocking the outgoing connection to the SMTP server, leading to authentication failure. Verify if there are any security programs causing interference and adjust their settings if needed.
  • SMTP Server Configuration: The issue might be on the server-side. Check if the SMTP server settings, including the server address, port number, and encryption method, are set up correctly.
  • Account Access: Ensure that the account you are trying to use for authentication has the necessary permissions to send emails via the SMTP server.
  • IP Address Blocking: If there were previous failed login attempts from the same IP address, the SMTP server might have temporarily blocked the IP for security reasons. In this case, waiting for a while and trying again might resolve the issue.
  • Two-Factor Authentication (2FA): If the email service provider or server enforces 2FA, you may need to generate an app-specific password or provide additional authentication credentials.

An App password is a 16-digit passcode that gives an app or device permission to access your Google Account. If you use 2-Step Verification and are seeing a "password incorrect" or "Cannot connect to SMTP Server" error when trying to access your Google Account, an App password may solve the problem.

To create an app password, you need 2-Step Verification on your Google Account. Here's a step-by-step guide to generate an app password for Gmail:

Enable Two-Step Verification:
  • Go to your Google Account settings (https://myaccount.google.com/).
  • Navigate to the "Security" section.
  • Under the "Signing in to Google" section, click on "2-Step Verification."
  • Follow the prompts to enable two-step verification for your Google account.
Generate App Password:
  • After enabling two-step verification, go back to the "Security" section in your Google Account settings.
  • Look for the "Signing in to Google" section again, and this time click on "App passwords."
  • You might be prompted to enter your Google account password again.
  • In the "Select app" dropdown, choose "mailer" (or "Other (Custom name)") if the "mailer" option is not available.
  • In the "Select device" dropdown, choose "Other (Custom name)."
  • Enter a custom name for your app password (e.g., "Contact Form").
  • Click on the "Generate" button.
Thank you for using our Ajax & PHP Contact Form.

Copyright © HTML Codex, All Rights Reserved.