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
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
- Download the .zip File and unzip it, on your localhost or on FTP-Server.
- If you have your own Form, just change your form
id="contactForm"
andaction="send.php"
- Than paste
script
codes down below yourform
- You have to also change the
input id
‘s too, but i use standart terms, maybe its same.
Explaining the Codes
- First i hide the Error Labels with using
display:none
- Importants to change:
action
If you want to change send.phpform-id
When you changed this, you have change inscript
too!
- Importants to change :
data:
If you changed form-idurl:
If you changed send.php, change this too.- 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.
- Here we are checking again the empty inputs, if someone blocks javascript.
We are taking precautions against XSS too with usingaddslashes
andstrip_tags
You don’t have to change here anything, if you didn’t changed any
input name
.
$mail->Host
Your SMTP Host. Most it is webmail.sitename.com or mail.sitename.com$mail->Port
In most case “25” is unsecure Port but fast, “465” secure Port, speed up to your Hosting Provider.- 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.
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!
Thank you.(Even if you’re Bot 🙂
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
Hey Steven, yeah sure. Just send me the contact-form part of your code or as you wish the ftp credentials: [email protected]
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?
that means you get from send.php some output:
if($mail->Send())
echo "";
}
Debug the send.php
The best tutorial! Thanks a lot, man. Greetings from Brazil.
Only an observation:
Fromname should be FromName.
Thank you for hint 🙂 it’s updated now.
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.
Merhaba, bu sayfanin türkçe versiyonuda var 🙂 Problemini yorum olarak yaz, beraber çözelim, ilerde ayni problemi yasayan biri olursa faydalanir 🙂
https://azizozbek.ch/blog/2017/11/php-ajax-iletisim-formu/
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.
hello, how can I add simple captcha numbers at this form?
Hi, you can use any kind of captcha solution for validation. for example:
https://github.com/LordDashMe/php-simple-captcha