Tuesday, June 23, 2015

Send E-mail using PHP and AngularJS

Implementing contact form in your website is a nice feature. The data of contact form can be stored in database or directly sent as e-mail.

Here are the steps to create e-mail contact form using php and AngularJS:
  1. Setup a gmail account to receive the contact e-mail. You can also setup Outlook or other account and change the below configuration accordingly.
  2. Create a page for contact form:
  3. We will including bootstrap.min.css and bootstrap font (//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet) in html first.
    Observe the following points in below code:
    • ng-submit="processForm()" will call preocessForm function
    • ng-class="{ 'has-error' : errorName }" is used for binding the error to class
    • Name, e-mail and content input field and Submit button.
    • formData.name, formData.superheroAlias and formData.content model created for name, email and content

  1. Set up JS - Observe following points in the code:
    • $scope.formData used to make glue between model and controller
    • $scope.processForm function making request to index.php to validate and send the e-mail
    • On success, the successful message and on failure, the error is assigned to property

  1. Set up PHP file - Observe following points in the code:
    • class.phpmailer.php is included and referred to send the mail
    • Validation of the values
    • $mail object and its property
    • If input field is valid then send the e-mail
    class.phpmailer.php will also using other classes, so we need to include class.phpmailer.php, class.pop3.php, class.smtp.php and PHPMailerAutoload.php. 


  1. The explanation is really good.Easy to Understand

  2. Hello. Do you enter the email you want the data to be sent to inside the Quotations?

    $mail->AddAddress(""); //Pass the e-mail that you setup

  3. Hello. Do you enter the email you want the data to be sent to inside the Quotations?

    $mail->AddAddress(""); //Pass the e-mail that you setup

    1. Hi.

      Probably a bit late but in PHP you would put your email address in single 'quotations'. I used a HTML to PHP method quite a bit differant to this but the synax I know would use ' ' ... I hope this helps someone in the future.

  4. Thank you nice explanation easy and simple.This article made my day...


  5. Hey there! I know this is kinda off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having problems finding one? Thanks a lot! netflix.com login

  6. The great service in this blog and the nice technology is visible in this blog. I am really very happy for the nice approach is visible in this blog and thank you very much for using the nice technology in this blog
    Angularjs course in chennai

  7. The blog you presented was very nice and interesting which helped me to get update on the recent technologies.

    angularjs training in chennai

    devops training in chennai

  8. I just needed to record a speedy word to express profound gratitude to you for those magnificent tips and clues you are appearing on this site. We are providing AngularJs training in Velachery.
    For more details: AngularJs Training in Chennai

  9. Hey, Your post is very informative and helpful for us.
    In fact i am looking this type of article from some days.
    Thanks a lot to share this informative article.
    QuickBooks Training in Hyderabad

  10. There may be some efficient alternatives available for the development of efficient website, but PHP web development fits the best.plakatų maketavimas

  11. This is a very amazing post for cheap web hosting services. in this post, you have provided all the basic information regarding.

    white label website builder

  12. Comfortabl y, the post is really the freshest on that deserving topic. I harmonise with your conclusions and definitely will thirstily look forward to your next updates.

    private label website builder

  13. Thank you for the link building list.I am going jot down this because it will help me a lot.Great blog! Please keep on posting such blog.

    website builder for reseller

  14. The PHP developers can without much of a stretch improve the web application's presentation by not executing database inquiries in circle. They additionally have various alternatives to achieve similar outcomes without executing database inquiries in circle.Why use Laravel

  15. I am really impressed the way you have written the blog Thank you so much for sharing the valueable post, I appreciate your hard work.Keep blogging.
    Angular JS Training in Electronic City
    Angular JS 2&4 Training in Electronic City