title: Send email using gmail smtp in zend?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5700470/email-zend-framwork-smtp">email zend framwork smtp</a>  </p>
  </blockquote>
  
  
  
  <p>I have following configuration:</p>
  
  <pre><code>smtp.type = Zend_Mail_Transport_Smtp
  smtp.smtpServer = "smtp.gmail.com"
  smtp.username = "ddd@gmail.com"
  smtp.password = "dddd"
  smtp.email = "ddd@gmail.com"
  smtp.port = "587"
  smtp.ssl = "tls"
  smtp.auth = "login"
  </code></pre>
  
  <p>I am getting following error:</p>
  
  <pre><code>5.7.0 Must issue a STARTTLS command first. 74sm813723wem.41
  </code></pre>
  
  <p>My COde:</p>
  
  <pre><code>public function sendEmail( $mailData, $bootstrap = null ) {
  
          // Get SMTP server configurations
          if ( $bootstrap == null ) {
              $front = Zend_Controller_Front::getInstance();
              $bootstrap = $front-&gt;getParam('bootstrap');
          }
          $smtpSettings = $bootstrap-&gt;getOption('smtp');
  
          print_r($smtpSettings);
  
          // Only pass username password settings if the authentication is required.
          if ( $smtpSettings['auth'] == 'login' ) {
  
              $config = array('ssl' =&gt; $smtpSettings['ssl'],
                          'username' =&gt; $smtpSettings['username'],
                          'password' =&gt; $smtpSettings['password']);
  
              $transport = new Zend_Mail_Transport_Smtp( $smtpSettings['smtpServer'], $config );
          } else {
              $transport = new Zend_Mail_Transport_Smtp( $smtpSettings['smtpServer'] );
          }
  
          $mail = new Zend_Mail( 'utf-8' );
  
          try {
  
              if ( $mailData['user'] == true ) { 
                  $mail-&gt;setFrom( $mailData['from'], $mailData['fromName'] );
  
              } else {
                    $mail-&gt;setFrom( $smtpSettings['email'], "eCHDP" );
              }
  
              // Do we have a single reciepent or multiple receipents?
              if ( !is_array($mailData['to']) ) {
                  $mail-&gt;addTo( $mailData['to'] , $mailData['toName'] );
              } else {
                  // We have multiple receipents. Add all of them.
                  foreach ( $mailData['to'] as $id =&gt; $value ) {
                      $mail-&gt;addTo( $value , $mailData['toName'][$id] );
                  }
              }
  
              $mail-&gt;setSubject( $mailData['subject'] );
              $mail-&gt;setBodyHtml( $mailData['body'] );
  
              // If attachment found then attach
              if ( $mailData['attachment'] ) {
                  $attach = new Zend_Mime_Part( file_get_contents( $mailData['attachment'] ) );
                  $attach-&gt;type = 'application/pdf';
                  $attach-&gt;disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
                  $attach-&gt;filename = 'Invoice.pdf';
                  $mail-&gt;addAttachment( $attach );
              }
  
              $mail-&gt;send( $transport );
  
              return true;
  
          } catch ( Exception $e ) {
              echo "Error sending Email : ";
              $logger = Zend_Registry::get('Logger');
              $logger-&gt;err($e-&gt;getMessage());
              echo $e-&gt;getMessage() . "\n\n\n";
              return false;
          }
  
      } 
  </code></pre>
  
  <p>Can someone guess that what is the error ? I can post code as well if required.</p>
  
  <p>Thanks</p>