title: Send mail via a contact form using phpmailer
body: <p>As I mentioned in title I want to Send mail With a contact form to gmail using phpmailer. I have written the code for my contact form and sendmail php file is given below.</p>
  
  <p>I am got error on sendemail.php file in the line $mail-> Port=465;</p>
  
  <p>contact.html</p>
  
  
  
  <pre><code>&lt;script type="text/javascript" src="jquery-2.1.4.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(function(){
  
  $('input[type=submit]').click(function(){
  
  $.ajax({
      url: "sendemail.php",
      type: 'POST',
      data: $("#myForm").serialize(),
      success: function(data){
         $('#result').html(data);
      }
  });
  
  });
  
  });
  &lt;/script&gt;
  
      &lt;form action="" method="post" onsubmit="return false;" id ="myForm"&gt;
            &lt;input type="text" class="form-control" required="required" name="guest_name" placeholder="Name"&gt;
            &lt;input type="text" class="form-control" required="required" name="guest_mail" placeholder="Email address"&gt;
            &lt;input type="text" class="form-control" required="required" name="guest_cont" placeholder="Contact No."&gt;
            &lt;input type="text" class="form-control" required="required" name="guest_comp" placeholder="Company Name"&gt;
            &lt;textarea name="guest_msg" id="message" required="required" class="form-control" rows="8" placeholder="Enquery or Feedback"&gt;&lt;/textarea&gt;
            &lt;input type="submit" name="submit" value="Submit" class="btn btn-danger btn-lg"&gt;
       &lt;/form&gt;
  </code></pre>
  
  <p>And sendemail.php</p>
  
  <pre><code>&lt;?php
  
  
      $subject = "Query/Feedback"; 
      $name = $_POST['guest_name']; 
      $email = $_POST['guest_mail']; 
      $contact = $_POST['guest_cont']; 
      $company = $_POST['guest_comp'];
      $message = $_POST['guest_msg']; 
  
      $email_from = $email;
      $email_to = 'rexxxxxxxxxxxxd@gmail.com';
  
      if($sender== '' || $mail_id== '' || $cont_no== '' || $company== '' || $msg_txt== ''){
          echo "check the fields";
      }else{
  
      $subject='Query from '.$sender;
      $message='Dear Sir,&lt;br&gt;&lt;br&gt;'.$msg_txt.'&lt;br&gt;&lt;br&gt;From: '.$sender.'&lt;br&gt;Contact: '.$cont_no.'&lt;br&gt;Company Name: '.$company;
  
      require "phpmailer/class.phpmailer.php";  //including the phpmailer file
  
      //Installing Class
      $mail = new PHPMailer();
  
      // Set up SMTP
      $mail-&gt;IsSMTP();
      $mail-&gt;SMTPAuth = true;
      $mail-&gt;SMTPSecure = "ssl";
      $mail-&gt;Host = "smtp.gmail.com;"
      $mail-&gt;Port = 465;
      $mail-&gt;Encoding = '7bit';
  
      // Authentication
      $mail-&gt;Username = "mymailid@gmail.com"
      $mail-&gt;Password = "mypassword"
  
      // Compose
      $mail-&gt;SetFrom($_POST['guest_mail'], $_POST['guest_name']);
      $mail-&gt;AddReplyTo($_POST['guest_mail'], $_POST['guest_name']);
      $mail-&gt;Subject = "/new Contact From Enquery"
      $mail-&gt;MsgHTML($guest_msg);
  
      // Send To
      $mail-&gt;AddAddress($email_to, "Banti");
      $result = $mail-&gt;Send();
      if($result)
          {
          echo "Thank you for your Feedback";
      }
  
      }
  
  
  ?&gt;
  </code></pre>