title: PHP on GoDaddy Linux Shared trying to send through GMAIL SMTP
body: <p>I have tried EVERY single script/code/method posted on StackOverflow and other sites for this, but with no luck. I am hosting on GoDaddy. I have setup a Google App account, set up everything needed for MX Records (using the GoDaddy tool for that), and even tried sending some emails from the GMAIL interface for my site, as well as through SMTP in terminal on one of my unix machines. It all worked.</p>
  
  <p>HOWEVER, when I try using PHP, it doesn't! Is it like GoDaddy blocking it somehow?</p>
  
  <p>I always receive:</p>
  
  <blockquote>
    <p>SMTP -> ERROR: Failed to connect to
    server: Connection refused (111) SMTP
    Error: Could not connect to SMTP host.
    Mailer Error: SMTP Error: Could not
    connect to SMTP host.</p>
  </blockquote>
  
  <p>Here's the code I am using for PHPMailer:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;PHPMailer - SMTP (Gmail) advanced test&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;?php
      require_once('../class.phpmailer.php');
      //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  
      $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
  
      $mail-&gt;IsSMTP(); // telling the class to use SMTP
  
      try {
          $mail-&gt;Host       = "smtp.gmail.com"; // SMTP server
          $mail-&gt;SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
          $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       = 465;                   // set the SMTP port for the GMAIL server
          $mail-&gt;Username   = "MYFROMADDRESSHERE";  // GMAIL username
          $mail-&gt;Password   = "MYFROMPASSWORDHERE";            // GMAIL password
          $mail-&gt;AddReplyTo('MYFROMADDRESSHERE', 'Sender Name');
          $mail-&gt;AddAddress('TESTTOADDRESSHERE', 'Recipient Name');
          $mail-&gt;SetFrom('MYFROMADDRESSHERE', 'Sender Name');
          $mail-&gt;AddReplyTo('MYFROMADDRESSHERE', 'Sender Name');
          $mail-&gt;Subject = 'PHPMailer Test Subject via mail(), advanced';
          $mail-&gt;AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
          $mail-&gt;MsgHTML(file_get_contents('contents.html'));
          $mail-&gt;AddAttachment('images/phpmailer.gif');      // attachment
          $mail-&gt;AddAttachment('images/phpmailer_mini.gif'); // attachment
          $mail-&gt;Send();
          echo "Message Sent OK&lt;/p&gt;\n";
      } catch (phpmailerException $e) {
          echo $e-&gt;errorMessage(); //Pretty error messages from PHPMailer
      } catch (Exception $e) {
          echo $e-&gt;getMessage(); //Boring error messages from anything else!
      }
      ?&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks!</p>