Aziz Ozbek
WordPress Expert from Zürich
php ajax contact form

Php Ajax Contact Form with PHPmailer

First of all download the Files (mail.zip)

In this Article we are gonna see how to create a contact form with using Ajax and Php.

In most case people create Contact Form, but it either doesn’t work or goes in Spam Box. That’s why i would like to share the Contact Form, which i use since years and work everytime 100%.

For using this Contact Form you dont have know anything special, just read the Guide and done. I capture a tutorial years ago, but in Turkish, thats why im gonna write down below a Guide.

I hope its helps 🙂

Backup-Video-Link: https://vimeo.com/157353491

phpmailer

What is PHPmailer ?

Phpmailer is a PHP class that can be used in PHP and prepares the appropriate environment by communicating with the mail server with the connection information that you specify to send an email to an email address.

The mail() function, which is the standard mail sending function of the PHP programming language, is currently disabled on all shared hosting services to prevent spam mails. However, it doesnt mean that mail cant be sent through the server. Alternatively, you can use a mailer script that communicates with the server via SMTP (Simple Mail Transfer Protocol) protocol and authenticates on the server.
Phpmailer is the best way to do this 🙂

How to use Php Ajax Contact Form

  1. Download the .zip File and unzip it, on your localhost or on FTP-Server.
  2. If you have your own Form, just change your form id="contactForm" and action="send.php"
  3. Than paste script codes down below your form
  4. You have to also change the input id‘s too, but i use standart terms, maybe its same.

Explaining the Codes

  1. First i hide the Error Labels with using display:none
  1. Importants to change:
    1. action If you want to change send.php
    2. form-id When you changed this, you have change in script too!
  1. Importants to change :
    1. data: If you changed form-id
    2. url: If you changed send.php, change this too.
    3. Control if you are using Jquery. If you have already Jquery in your Page, check out which one works for boths. Sometimes there is conflict cause two Jquery Libraries.
  1. Here we are checking again the empty inputs, if someone blocks javascript.
    We are taking precautions against XSS too with using addslashes and strip_tags

    You don’t have to change here anything, if you didn’t changed any input name.

  1. $mail->Host Your SMTP Host. Most it is webmail.sitename.com or mail.sitename.com
  2. $mail->PortIn most case “25” is unsecure Port but fast, “465” secure Port, speed up to your Hosting Provider.
  3. I think the other Codes are obvious, just change the information with yours.

Most Important Part is here.

Just don’t forget to change line 49 public $From to your Mail address.

public $FromName is the Subject, which going to show in Inbox as a Header.

ajax-php-contact-form

ajax-contact-form

ajax-contact-form

Rating: 4.6/5. From 10 votes.
Please wait...

14 comments

  1. Greetings from Colorado!
    I’m bored too death at work so I decided to check out yoour website on my iphone during lunch break.
    I really like the knowledge you present here and can’t wait to take a look when I get home.
    I’m surprised at how quick your blog loaded on my phone .. I’m not efen using WIFI, just 3G ..
    Anyways, fantastic blog!

  2. Hallo Azizuallah I have made a web, everything works fine except the contact form that displays “Email was successfully sent”, but in fact it never was sent.
    The template came with Ajax and JS query, the web has all the Html but i think it’s the connection between the PHP script I put in …it just does not send.
    If I send you the FTP codes and my email address where I would like the contact form to deliver, could you wire it up please and make it work, if you have some free time ? Sincerely Steven

  3. Hi man. I use your code and is fantastic.

    Just one thing, I keep to receive message “there is an error”, but everything is Ok and mail is correctly sended.

    How is possible?

  4. Aziz dostum merhaba, Türk olduğunu görünce yazmak istedim. PHPMailer ve Java Script kod çakışması ile ilgili bir sorunum var. Rica etsem mail adresimden bana ulaşıp yardımcı olur musun, çok makbule geçer.

  5. Do you need help with graphic design – brochures, banners, flyers, advertisements, social media posts, logos etc.?

    We charge a low fixed monthly fee. Let me know if you’re interested and would like to see our portfolio.

Leave a Reply

Your email address will not be published. Required fields are marked *