title: PHPMailer Mailer Error: Message body empty
body: <p>I'm trying to get the basic example working for PHPMailer.</p>
  
  <p>All I done was upload the whole PHPMailer_5.2.2 folder, configured the page below as per the code you see and I keep getting <code>Mailer Error: Message body empty</code>, but I can clearly see the contents.html file has html in it and isn't empty. This is the example file I'm using from the PHPMailer PHPMailer_5.2.2/examples/test_smtp_gmail_basic.php</p>
  
  <p>I tried using the settings I have in Outlook for Gmail that works, I know my username and password, the SMTP port is 587 and it's set to TLS, I tried replacing SSL with TLS in the code below, I still get same error.</p>
  
  <p>I also tried the following code, which has been suggested:</p>
  
  <p>changed this:</p>
  
  <pre><code>$mail-&gt;MsgHTML($body);
  </code></pre>
  
  <p>to this</p>
  
  <pre><code>$mail-&gt;body = $body;
  </code></pre>
  
  <p>I still got same error, is there something else I need to configure? It's my first time using PHPMailer, I can get the standard php mail working, but I want to try this because the page I'm going to be emailing has lots of html and I don't want to have to go through all the html and enter character escapes so someone recommending using this.</p>
  
  <pre><code>&lt;?php
  
  //error_reporting(E_ALL);
  error_reporting(E_STRICT);
  
  date_default_timezone_set('America/Toronto');
  
  require_once('../class.phpmailer.php');
  //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  
  $mail             = new PHPMailer();
  
  $body             = file_get_contents('contents.html');
  $body             = preg_replace('/[\]/','',$body);
  
  $mail-&gt;IsSMTP(); // telling the class to use SMTP
  $mail-&gt;Host       = "smtp.gmail.com"; // SMTP server
  $mail-&gt;SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                             // 1 = errors and messages
                                             // 2 = messages only
  $mail-&gt;SMTPAuth   = true;                  // enable SMTP authentication
  $mail-&gt;SMTPSecure = "ssl";                 // sets the prefix to the servier
  $mail-&gt;Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail-&gt;Port       = 587;                   // set the SMTP port for the GMAIL server
  $mail-&gt;Username   = "xxx@gmail.com";  // GMAIL username
  $mail-&gt;Password   = "xxx";            // GMAIL password
  
  $mail-&gt;SetFrom('xxx@gmail.com', 'First Last');
  
  $mail-&gt;AddReplyTo("xxx","First Last");
  
  $mail-&gt;Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";
  
  $mail-&gt;AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  
  $mail-&gt;MsgHTML($body);
  
  $address = "xxx.net";
  $mail-&gt;AddAddress($address, "John Doe");
  
  //$mail-&gt;AddAttachment("images/phpmailer.gif");      // attachment
  //$mail-&gt;AddAttachment("images/phpmailer_mini.gif"); // attachment
  
  if(!$mail-&gt;Send()) {
    echo "Mailer Error: " . $mail-&gt;ErrorInfo;
  } else {
    echo "Message sent!";
  }
  
  ?&gt;
  </code></pre>