title: Email settings for sending email in PHP through custom domain on gmail
body: <p>I have a custom domain setup on gmail for mail.</p>
  
  <p>I have hosted my website on a different hosting provider and I'm using CodeIgniter and PHP to send an email through my account.</p>
  
  <p>What are the settings I need to enable sending mail (from a contact form) through my gmail account?
  And what code do I need to use?</p>
  
  <p>Update:
  What I've tried is the following:
  - Create a new email account (@gmail.com, not custom)
  - Enable 2 step verification
  - Generated an app-specific password
  - Used this to send the email
  Even this is not working.</p>
  
  <p>Here's the code I'm using:
      
  
  <pre><code>$mail = new PHPMailer;
  
  $mail-&gt;IsSMTP();                                      // Set mailer to use SMTP
  $mail-&gt;Host = 'ssl://smtp.googlemail.com';  // Specify main and backup server
  $mail-&gt;SMTPAuth = true;                               // Enable SMTP authentication
  $mail-&gt;Username = 'samesenderaccount@gmail.com';                            // SMTP username
  $mail-&gt;Password = 'appspecificpassword';                           // SMTP password
  $mail-&gt;SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
  $mail-&gt;Port = 465;   
  
  $mail-&gt;From = 'samesenderaccount@gmail.com';
  $mail-&gt;FromName = 'Mailer';
  $mail-&gt;AddAddress('samesenderaccount@gmail.com', 'Info');  // Add a recipient
  //$mail-&gt;AddAddress('ellen@example.com');               // Name is optional
  $mail-&gt;AddReplyTo('other@gmail.com', 'From Try');
  //$mail-&gt;AddCC('cc@example.com');
  //$mail-&gt;AddBCC('bcc@example.com');
  
  $mail-&gt;WordWrap = 50;                                 // Set word wrap to 50 characters
                                  // Set email format to HTML
  
  $mail-&gt;Subject = 'Here is the subject';
  $mail-&gt;Body    = 'This is the HTML message body in bold!';
  
  if(!$mail-&gt;Send()) {
     echo 'Message could not be sent.';
     echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
     exit;
  }
  
  echo 'Message has been sent';
  ?&gt;
  </code></pre>