title: Using PHPMailer and Amazon SES
body: <p>I am using <strong>Amazon SES</strong>. I am trying to send an email from my <strong>PHP</strong> script using <strong>PHPMailer</strong>.</p>
  
  <p>I already verified <em>two</em> email ids and trying to send mail from and to this mail ids. But It throws the following error.</p>
  
  <h2><strong>ERROR</strong></h2>
  
  <pre><code>SERVER -&gt; CLIENT: 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-693939519  QEPGeLndQQq5vJ53VMXU
  CLIENT -&gt; SERVER: EHLO localhost
  SERVER -&gt; CLIENT: 250-email-smtp.amazonaws.com250-8BITMIME250-SIZE 10485760250- STARTTLS250-AUTH PLAIN LOGIN250 Ok
  CLIENT -&gt; SERVER: STARTTLS
  SERVER -&gt; CLIENT: 220 Ready to start TLS
  CLIENT -&gt; SERVER: EHLO localhost
  SERVER -&gt; CLIENT: 250-email-smtp.amazonaws.com250-8BITMIME250-SIZE 10485760250-STARTTLS250-AUTH PLAIN LOGIN250 Ok
  CLIENT -&gt; SERVER: AUTH LOGIN
  
  
  SMTP NOTICE: EOF caught while checking if connected
  SMTP connect() failed.
  Mailer Error: SMTP connect() failed.
  </code></pre>
  
  <h2>The following is my <em>PHP Script</em>:</h2>
  
  <pre><code>&lt;?php
  
  //SMTP needs accurate times, and the PHP time zone MUST be set
  //This should be done in your php.ini, but this is how to do it if you don't have   access to that
  date_default_timezone_set('Etc/UTC');
  
  require 'phpmailer/PHPMailerAutoload.php';
  
  //Create a new PHPMailer instance
  $mail = new PHPMailer();
  
  //Tell PHPMailer to use SMTP
  $mail-&gt;isSMTP();
  
  //Enable SMTP debugging
  
  $mail-&gt;SMTPDebug = 2;
  
  //Ask for HTML-friendly debug output
  $mail-&gt;Debugoutput = 'html';
  
  //Set the hostname of the mail server
  $mail-&gt;Host = 'email-smtp.us-east-1.amazonaws.com';
  
  //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  // I tried PORT 25, 465 too
  $mail-&gt;Port = 587;
  
  //Set the encryption system to use - ssl (deprecated) or tls
  $mail-&gt;SMTPSecure = 'tls';
  
  //Whether to use SMTP authentication
  $mail-&gt;SMTPAuth = true;
  
  //Username to use for SMTP authentication - use full email address for gmail
  $mail-&gt;Username = "SES Secret ID";
  
  //Password to use for SMTP authentication
  $mail-&gt;Password = "SES Secret Key";
  
  //Set who the message is to be sent from
  $mail-&gt;setFrom('sender@example.com', 'sender');
  
  //Set who the message is to be sent to
  $mail-&gt;addAddress('receiver@example.com', 'receiver');
  
  //Set the subject line
  $mail-&gt;Subject = 'PHPMailer GMail SMTP test';
  
  
  $mail-&gt;Body = 'This is a plain-text message body';
  //Replace the plain text body with one created manually
  $mail-&gt;AltBody = 'This is a plain-text message body';
  
  //send the message, check for errors
  if (!$mail-&gt;send()) {
      echo "Mailer Error: " . $mail-&gt;ErrorInfo;
  } else {
      echo "Message sent!";
  }
  ?&gt;
  </code></pre>
  
  <p>I tried so many solutions I found over the internet, especially <strong>stackoverflow</strong>.</p>
  
  <p>Nothing works !! </p>