title: SendGrid SMTP integration with contact form
body: <p>I want to use SendGrid SMTP services to send emails from my website's contact form. The submit button on the form just spits out a blank version of my website, with no emails sent to my inbox. </p>
  
  <p>Here's the PHP code:</p>
  
  <pre><code>&lt;?php
  
  require("class.phpmailer.php");
      $mail = new PHPMailer();
  
      // SMTP &amp; Sendgrid settings
      $mail-&gt;IsSMTP();
      $mail-&gt;Host = "smtp.sendgrid.net";
      $mail-&gt;Port = "465";
      $mail-&gt;SMTPAuth = "true";   // Enable SMTP authentication
      $mail-&gt;Username = "sendgrid username";
      $mail-&gt;Password = "sendgrid password";
      $mail-&gt;SMTPSecure = ''; // Enable encryption, 'ssl' also accepted
  
      // Email headers and body
      $mail-&gt;SetFrom("abc@123.com");
      $mail-&gt;AddAddress("abc@123.com");
  
      // Form fields
          $Name = $_POST['Name'];
          $Email = $_POST['Email'];
          $Contact = $_POST['Contact'];
          $Message = $_POST['Message'];
  
  
      $mail-&gt;Subject  = "Message from yoursite.com";
      $mail-&gt;Body     = "You have a new message from your contact form on site.com \n \n Name: $Name \n Email: $Email \n Contact: $Contact \n Message: $Message";
      $mail-&gt;WordWrap = 50;
  
  
      if(!$mail-&gt;Send()) {
        echo 'Message was not sent.';
        echo 'Mailer error: ' . $mail-&gt;ErrorInfo;
      }
      else {
        echo 'Message has been sent.';
      }
  header('Location: mywebsite.com');
   ?&gt;
  </code></pre>