You are here:
< Back

If you do not want to install it by yourself, I provide the installation service. You can buy it here.

In this tutorial, I will show you how to add AJAX & PHP code to send emails using Simple Contact Form.

Prerequisites

To follow this tutorial, you need:
1. A Templatemo or Tooplate Template (I will be using Templatemo 536 Dream Pulse in this example.)

** Note ** If you’re using the Pop Design template, please follow this tutorial instead.


2. Contact Form

Extract both zip files and follow the steps below.

1. Copy Files

From contact-form folder to templatemo_536_dream_pulse folder, copy send-email.php to root folder and js/send-email-ajax.js to js folder.

Note: If your template’s js folder doesn’t already have jquery.min.js, also copy it from the contact form folder.

2. Contact Form Scripts

  1. Open templatemo_536_dream_pulse/index.html file in a text editor. Add id="contact-form" inside <form> at line 336. For Contact Form with Attachment, also add enctype="multipart/form-data"
  2. From contact-form/index.html file, copy code from line 32-34 and paste it in templatemo_536_dream_pulse/index.html file at line 347. For Contact Forms with Spam Filter, also copy and paste the code from line 29-32.
  3. Also in templatemo_536_dream_pulse/index.html, add <script src="js/send-email-ajax.js"></script> before the closing</body>tag. Save and close.
Contact Form Scripts
Click on the image to zoom in

4. Open templatemo_536_dream_pulse/send-email.php in a text editor.

For Contact Form with Attachment:

At lines 7 & 8, replace with your allowed file types and recipient email respectively. Save and close.

For Simple Contact Form:

At line 2, replace with your email. Save and close.

send-email.php

3. Upload to Your Server and Test

Upload templatemo_536_dream_pulse files to your web host and test the form.
You should receive the test message in your email shortly.

134 Comments

  1. I followed these directions but I still can’t get it to work. I am using Templatemo 503 Newline

    Reply
  2. Hi!
    I need some help. Everything ok, but if send a message from mobile browser, all of mails land in spam.

    Reply
  3. Hello
    Can you help me ?
    I made the changes on templatemo_537_art_factory original, but impossible to make it work!

    Reply
  4. I just made the change, but it still doesn’t work, when I click send, I have a return home page. In private perhaps?

    Reply
  5. works great except for 1 litle problem..
    I have set the email to: address in line 2 of the send-email.php to my gmail accoount as I cannot get it to work to my wifes busines account of
    info@amitylabardoodles.com.au
    Is there a string holding the email adress that is set too short?
    I have tried other address without any problems. Could you please shed some light on this.
    Thanks

    Reply
  6. Hi, it doesn’t work. I am using the ‘templatemo_454_compass’ template. I also uploaded the contact-form itself with no modifications and is not working (http://lapaleotta.com/contact-form/index.html). Can you help me?

    Reply
    • Hi Federico,
      There seems to be something wrong with your send-email.php file. Could you send me that file? clock at learnteachcenter dot com.

      Reply
  7. I have “Tinker Free Website Template” and I added the “contact-form” and could not get it to work. It errors and gives the error message every time.
    I have followed the instructions above.

    Reply
  8. Hi, I’m trying to use the files in templatemo_540_lava_landing_page and it won’t send. I’m also trying to have the submit button link to another html page.

    I have checked the junk and spam folders of my email and tested half a dozen times with no success.

    Can you please help?

    Reply
    • Hi Anthony,

      Did you receive an error message when you submit the form?
      Could you send index.html & send-email.php to clock at learnteachcenter dot com?

      Reply
  9. Hello,
    The form is not working. Any help ?

    Reply
  10. Hi
    the form works, and now I tried to add the functionality to add an attachment to the email, but I fail. can you support? any tutorial which can help?

    Reply
  11. Hello,

    After all thank you for the template.
    I use the temple 2097-pop from tooplate. I think I follow the instructions but I don’t find why it doesn’t work.
    Does the website have to be online to work or it can work locally ?

    Reply
    • Hello Olivier,
      Thank you for your contact form purchase.
      The website has to be online to work. However, the 2097-pop template requires some modifications to the code. Can you send your website files to clock at learnteachcenter dot com?

      Reply
  12. What do you meed about clock ?

    Reply
  13. This doesn’t work. Once I submit the form I’m brought back to the top of the home page with no result message. And no email in the spam folder or inbox. Template 537.

    Reply
    • Hi,
      send-email-ajax.js is missing in your js folder. Please check.

      Reply
      • I missed that. Thank you. But it’s still not working. Do I need to set the URL in the send-email-ajax.js to point to the directory of send-email.php?

        Are you able to continue this support via email?

        Reply
        • No, but send-email.php file must be in the same folder as index.html file.

          Yes, I can continue this support via email. My email is clock at learnteachcenter dot com.

          Reply
  14. can you please help me with template 453_outline. Send message is not working in stay in touch part

    Reply
  15. Absolutely the best customer support I have ever encountered. Bar none.

    Diligently helped me get my Simple Contact Form working on my web site. The best money I’ve ever spent on software.

    Kudos to you Aye Aye Mon.

    Reply
  16. Hello. I haven’t been able to get this to work just yet. When I put the

    Send result message will display here.

    It inserts a green box on top of my “Send Message” button. Also, when I send the message it just refreshes the page. I’m not positive what I am doing wrong here. Any help would be much appreciated.

    Reply
    • Hello Drew,
      I have tested your contact form and it works fine. To hide the green message before sending, please add the following code to the end of the templatemo-style.css file.
      .d-none { display: none; }

      Reply
      • Green Box is now gone, but I still haven’t received an email yet from the form. It shows that the message has been sent successfully and I have tried sending to different email addresses by changing the send email script. Could you please help me figure this one out? I can send you my files if you need. Thanks so much.

        Reply
  17. I checked the spam folder and it isn’t there either.

    Reply
  18. 1) in the send-email.php file, how to add two email addresses to receive a visitor’s form submission? for example, one copy goes to the webmaster, another copy goes to a company employee?

    Reply
  19. My sent email concept is not working, I email you. Template:templatemo_537_art_factory
    Kindly do the needful
    very urgent

    Reply
  20. Hi, could you please me, an error message pop out like below:

    Notice: Undefined variable: body in /storage/ssd2/917/13603917/public_html/send-email.php on line 8 success

    Reply
  21. hola , su ayuda por favor , compre el

    Simple-Contact-Form
    — See the installation instructions at https://www.ltcclock.com/knowledge-base/simple-contact-form/

    pero no lo puedo instalar , lo necesito para el template Hydro_509, por favor su ayuda. gracias

    Reply
  22. I am unable to get the simple contact form to work correctly. I am using the tooplate page template located here: https://www.tooplate.com/view/2107-new-spot
    The error page that is generated refers to the following: HTTP Error 405.0 – Method Not Allowed
    The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
    The site is hosted on Azure.
    Please assist.

    Reply
    • Hi John,
      Thanks for your purchase!
      I checked your website and found that the jquery file is missing.
      Please copy and paste jquery.min.js file to the js folder and in the index.html file, import jquery.min.js above the send-email-ajax import.
      Import jquery above send-email-ajax.

      Reply
  23. Hi !

    Works perfectly, thank you for your work.

    Is there a way to modify the color of the text and background of the success message (green) ?

    Reply
    • Hi David,

      Thanks for your purchase and comment!

      You can modify the colors by adding a new CSS rule to your CSS file like so:

      .alert-success {
      color: #fff;
      background-color: #5bc0de;
      }

      Reply
  24. Thank you for your reply.

    Sorry to bother you but :

    Should I add this in this file ? css/tooplate-infinite-loop.css

    As this it looks like not changing anything 🙁

    Reply
  25. I keep getting an error when I test the form on my site. Please help!

    Reply
  26. I just edited my templatemo_504_page_one webpage using the provided files. It worked – no issues! I’d spent hours attempting to use other contact forms code, Ajax, JS files, PHP- and could not get anything to work. Thanks so much.

    Reply
  27. I bought and applied the contact form, which was kind of tricky to understand since I used another theme from TemplateMo (528 Elegance)
    At first I always got the error “Something went wrong :(” and now after fiddling around I just realized I can only use an email that ends with the websites url and IS existing.
    For example, my website is called “thisismywebsite.com” and I have these mail accounts for it:
    info@thisismywebsite.com
    admin@thisismywebsite.com

    I can only send an email and receive it without error when inserting one of these existing email accounts as sender.

    I CAN NOT use for example “myaccount@googlemail.com”, “ceo@someotherwebsite.com” or something else. I always get errors than. I can only use EXISTING email accounts of the same domain I am using the contact form.

    I hope you understand and can help me. This makes no sense to me.
    My website previously used wordpress with a fully functional contact form from wordpress and I just rebuild everything in the template and implemented the bought contact form. So it should’nt be a servers/hosters problem, or is it ?

    Reply
    • It is the configuration of your mail server. As for your WordPress contact form, could you set any sender email address and receive it as “From” email?

      To solve it, in the send-email.php you can set “from” email to an approved email address and then include the sender email in the message body and as a “reply to” field.
      If you want me to do it, please send your file to clock at learnteachcenter dot com.

      Reply
  28. Regards

    I’m using the template https://www.tooplate.com/view/2119-gymso-fitness … Give me the setup instructions

    Thank you

    Reply
    • Hello,
      Thank you for your purchase. You can follow the instructions above. When you finish, please send me your “index.html” file to clock at learnteachcenter dot com. I will check it for you.

      Reply
  29. Hey I just added google recaptcha v2 to the form and it works, but I have no idea how I can remove the recaptcha response from the mail
    Every mail I receive now has “g-recaptcha sumcodeicuahdsiasdiasidgaisgsdiagduaguedfgue” in it.
    Any way I can filter a specific input field, in this case the g-recaptcha, out from the mail ?

    I hope you understand my problem

    Reply
    • Hi,
      Could you please tell me the email address you used to purchase the form?

      Reply
      • it’s //daikiri 94 -at- googlemail com//

        Reply
        • Thank you for the confirmation.
          In send-email.php, inside foreach loop, above $body line, add the following code:

          if($param_name == ‘g-recaptcha’) {
          continue;
          }

          Reply
          • Hey I just tried and it doesn’t work. The exact output in the mail is “G-recaptcha-response: blablablablabla”

            This is the code I edited with your advice:

            foreach ($_POST as $param_name => $param_val) {
            if($param_name == ‘G-recaptcha-response’) {
            continue;
            }
            $body .= ucwords(str_replace(“_”, ” “, $param_name)) . “: ” .
            $param_val . “\n”;
            }

            did I do anything wrong ? Mail looks like this:

            Name: Test
            Email: test@test.com
            Nachricht: testmessage
            G-recaptcha-response: 45dwe51wece15-fe54f15wef51ew5-1f5e61f6ew1f6we1f61ew56f1ds23f1e56f1-156fe1wf516ew6f1we51fe

          • Please try smallcase “g” like this:
            if($param_name == ‘g-recaptcha-response’) {
            continue;
            }

          • Thank you very much. It works now!

            May be you can help me with my last problem for now:

            When receiving mails form germany, UTF 8 is not present. So “äöü” wont be displayed correctly in my mail program.

            I also googled how to get it to work, but I just can’t figure it out. This would be very important for me because it’s a german website.

            Any help ?

          • Did you set in index.html at the top?

          • Yes I set it in the html. May be my code is wrong? What exactly has to be added?

          • Could you send me your website files and sample German text to test? info at ltcclock dot com.

          • Hey again. I just did it! It works!
            For anyone having the same problem, the code in send-email.php is now following:

            if($replyTo != “”) {
            $headers = ‘From: ‘.$from.”\r\n” .
            ‘Reply-To: ‘.$replyTo.”\r\n” .
            —> ‘Content-Type: text/plain; charset=UTF-8’ .”\r\n” .
            ‘X-Mailer: PHP/’ . phpversion();

            the “right-arrow” points to the line I added into the existing code.

  30. Hello. I am curious if you could take a look at my script to let me know if my contact form that I purchased is configured correctly. I don’t mind sending you my source files. Could you please help me as everything else on the website is working great. But I can’t get the green success box when my message is sent and the page just refreshes. Thanks.

    Reply
  31. Can you help me with spam messages?

    Reply
    • The form contains a hidden field. That field is visible to spambots but not to humans. Spambots will fill in all the fields but humans will leave that field empty. So, if the hidden field is filled in, an email won’t be sent.

      Reply
  32. I had in mind the problem that the messages from the form end up in spam. Sorry

    Reply
  33. Hi, please I purchased the contact form code, but am now getting an error message on my contact page each time a message is sent, it says an error occurred

    Reply
    • Hi,
      Thanks for your purchase. What is your website URL? When I visit creativitywebs.com, I received the following error:
      “This site can’t be reached
      Check if there is a typo in creativitywebs.com.
      DNS_PROBE_FINISHED_NXDOMAIN”

      Reply
  34. creativitywebs.com the problem is resolved now

    Reply
  35. Hi
    I have followed instructions on your site but I am using a different template https://templatemo.com/tm-396-smoothy

    When pasting in the contact form I get a field I can not remove it displays in the form as
    Leave this empty:
    Your URL

    If I fill in both fields with my email address the form says it has been successful however I still don’t receive an email .

    I have amended the php file and uploaded to my site ….. bit stuck what to try next

    Reply
    • Hi John,
      Thanks for your purchase.
      You should not fill in any value in that field. It was meant to trap spambots.
      Please add the following code to the end of css/templatemo_style.css.
      .d-none { display: none; }
      What did you change in the PHP file? You shouldn’t remove the URL field check.

      Reply
    • The form contains a hidden field. That field is visible to spambots but not to humans. Spambots will fill in all the fields but humans will leave that field empty. So, if the hidden field is filled in, the email won’t be sent.

      Reply
  36. Wykona?em zgodnie z zaleceniem PROSTY FORMULARZ i po wys?aniu wiadomo?ci z formularza pojawia si? komunikat: Something went wrong 🙁

    Reply
    • Hi,
      Does your web host support PHP and the mail function? I got an error message when sending the request to the send-email.php file. The error says “401 (Authorization Required)”.

      Reply
  37. the form does not work: you can enter data, but it does not go anywhere

    Déjanos un mensaje

    Send result message will display here.

    Enviar

    Reply
  38. Hi. It returns a 405 error on the server and doesn’t send, is there some additional configuration steps that have been missed in this tutorial?

    Reply
  39. Hi Aye Aye!
    Thanks, all works well.
    But I have one problem: in German we have “Umlaute” like “ä, ö, ü”.
    For this I need to place a “charset (UTF-8)” in your code.
    Where would I do that?

    Thanks in advance for your reply!

    Reply
    • Hi Joe,

      Another user, Marco, had the same problem and he posted his solution above. Here it is:

      “For anyone having the same problem, the code in send-email.php is now following:

      if($replyTo != “”) {
      $headers = ‘From: ‘.$from.”\r\n” .
      ‘Reply-To: ‘.$replyTo.”\r\n” .
      —> ‘Content-Type: text/plain; charset=UTF-8’ .”\r\n” .
      ‘X-Mailer: PHP/’ . phpversion();

      the “right-arrow” points to the line I added into the existing code.”

      Reply
  40. Hello !
    What is the Spam filter ? and how does it work ?

    Reply
    • Hello Julien,
      The spam filter will filter out the messages sent by spambots. It works by having an input field, which is not visible to humans but visible to spambots. So, if the hidden field is filled in, it means that the message is from spambots and will not be sent.

      Reply
  41. Hello Aye,
    Does it work with firebase as I have my hosting in there?

    Reply
  42. Hello Aye Aye
    Will it work with firebase? As I have my hosting overthere.

    Thank you
    Regards,

    Reply

Leave a Reply

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